Issue Domain can't send emails

Discussion in 'Plesk 12.x for Linux' started by Irolan, Aug 23, 2016.

  1. Irolan

    Irolan New Pleskian

    1
    70%
    Joined:
    Oct 7, 2015
    Messages:
    9
    Likes Received:
    0
    Hello,
    weird problem here.
    We're running a Plesk 12.5.30 Update #41 on CentOS Linux 7.1.1503 (Core). There's several domains on the system, all of which work fine, but one. A certain domain does not permit sending emails.
    The emails are Office365, so they're not Plesk - the email server function is turned off for the domain.
    Drupal is installed on the domain, but it's not a Drupal problem - I tested the mail function using this script:
    PHP:
    <?php
    $to 
    "me@mydomain.abc";
    $subject "Test Mail";
    $message "This is a test";
    $from "office@mydomain.abc";
    $headers "From:".$from;
    if(
    mail($to$subject$message$headers)){
        echo 
    "Mail sent.";
    }
    else{
        echo 
    "Error";
    }
    ?>
    It returns "Error".
    There's nothing in the protocols.
    Does anyone have an idea what might be the problem?
     
  2. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    959
    Likes Received:
    28
    Location:
    Romania
    Try to send out with SMTP the emails.

    Anyway, check 2 things.
    - in Server-Wide Mail Settings check if you allow to send out with sendmail email, like: Allow users and scripts to use Sendmail
    - Email services are active for the domain.

    Always check the error_logs to see what can be the reason.
     
  3. Irolan

    Irolan New Pleskian

    1
    70%
    Joined:
    Oct 7, 2015
    Messages:
    9
    Likes Received:
    0
    How?

    Users and scripts are allowed to use sendmail, that option is active.
    The email services for the domain in question are deactivated - that's intentional as there are no email addresses set up for the domain in Plesk. They're in Office365. I activated the email services anyway as a test - no change. Also, there are two other domains with a similar setup (emails are Office365, email services in plesk are deactivated) and they work.

    Unless there's additional logs I don't know about, there's nothing there. I checked under "protocols" in the domain settings - it shows when the test.php with the mail script was accessed, but nothing further.
    Drupal only says that an error has occured and the email could not be sent, but not what the error was.
     
  4. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    959
    Likes Received:
    28
    Location:
    Romania
  5. Irolan

    Irolan New Pleskian

    1
    70%
    Joined:
    Oct 7, 2015
    Messages:
    9
    Likes Received:
    0
    This is not a Drupal issue. I tried the SMTP mailer module for Drupal, still the same problem. It says there was an error.
    I could not find anything in the error logs of the domain. The mail log is not available because the mail services are turned off for the domain.
     
  6. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    959
    Likes Received:
    28
    Location:
    Romania
    If you have tried the SMTP mailer, then probably you are using your external services. Then it is not connected anymore to your server.
    What are the settings used for SMTP? Server, port, etc (do not copy the password or replace also the domain.)
     
  7. Irolan

    Irolan New Pleskian

    1
    70%
    Joined:
    Oct 7, 2015
    Messages:
    9
    Likes Received:
    0
    Username and password for SMTP are the email (in this case office@thewebsitesdomain.de) and password of the Office365 account.
    SMTP server is smtp.office365.com
    Outgoing port is 587
    I tried both SSL and TLS.
     
  8. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    959
    Likes Received:
    28
    Location:
    Romania
    Then this means that you are using an external service. If you do not get back errors in Drupal, then I do not see how you can debug it. You should get back the server response, which should be in some Drupal logs and you must see there the issue. PLESK/Server does not have anything to do with it in my opinion. It is same like you are using a mail software. Mail software always show to you an error, like invalid password or cannot connect to server or etc.
    If you have tried port SSL and TLS also you need to be sure you have a certificate accepted or you will get error. Try to find some errors in Drupal Log.
     
  9. Irolan

    Irolan New Pleskian

    1
    70%
    Joined:
    Oct 7, 2015
    Messages:
    9
    Likes Received:
    0
    Well, it is not Drupal. As you can see in my initial post, I tried a script. This script was simply a PHP file accessed via http://mydomain.de/test.php and it did not work. If it was a problem with Drupal, the the script would stikk work.
    The Drupal log also only states "There was an error while sending the email. Please contact you web administrator."
    I'll try to find if there's any problem with Office365. But everything else seems to work there as well.
     
  10. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    959
    Likes Received:
    28
    Location:
    Romania
    In your test script you are not using SMTP, in this case you can see errors in maillog and error_log.

    If you are using SMTP in other script then you need to get back an error.

    It is hard to know like this what you are doing, or also to tell to you where is the error. Eventually contact me on PM and I will try to help you out.
     
  11. UFHH01

    UFHH01 Plesk addicted! Plesk Guru

    43
    64%
    Joined:
    Jun 11, 2013
    Messages:
    5,380
    Likes Received:
    1,163
    Location:
    Hamburg / Germany
    Here is an example PHP script, with SMTP - AUTH - functionality for OFFICE365 ( pls. adjust the EXAMPLE - entries, if you want this script to work as expected! ;) ), which you could place temporarily in the docroot - of your domain/subdomain ( for example at "/var/www/vhosts/YOUR-DOMAIN.COM/httpdocs/test-phpmail.php" ).

    Code:
    <?php
        require_once('/usr/share/php/Mail.php');
    
        $from = "FROM-EXAMPLE-FIRST-NAME FROM-EXAMPLE-LAST-NAME <FROM-EXAMPLE@YOUR-OFFICE365-EMAIL-ADRESS-DOMAIN.COM>";
        $to = "TO-EXAMPLE-FIRST-NAME TO-EXAMPLE-LAST-NAME  <TO-EXAMPLE@YOUR-DESTINATION-EMAIL-ADRESS-DOMAIN.COM>";
        $bcc = '';
        $subject = "TEST - eMail with PHPmail - usage";
        $body = "SUCCESS,\n\nYOU SUCCESSFULLY RECEIVED AN EMAIL WITH PHPmail AND OFFICE365.";
    
        $host = 'smtp.office365.com';
        $port = '587';
        $username = 'EXAMPLE-OFFICE365-AUTH-USERNAME';
        $password = 'EXAMPLE-OFFICE365-AUTH-PASSWORD-FOR-THE-CONFIGURED-OFFICE365-EMAIL-ADRESS';
    
        $headers = array(
        'Port'          => $port,
        'From'          => $from,
        'To'            => $to,
        'Subject'       => $subject,
        'Content-Type'  => 'text/html; charset=UTF-8'
        );
    
        $recipients = $to.", ".$bcc;
    
        $smtp = Mail::factory('smtp',
        array ('host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password));
    
        $mail = $smtp->send($recipients, $headers, $body);
    
        echo "test";
    
        if (PEAR::isError($mail)) {
        echo("<p>" . $mail->getMessage() . "</p>");
        } else {
        echo("<p>Message successfully sent!</p>");
        }
    
    ?>
    Depending log - entries will be written to to "/var/log/maillog"
     
    Last edited: Aug 26, 2016
    lvalics likes this.
  12. Peter Debik

    Peter Debik Golden Pleskian Plesk Guru

    34
    30%
    Joined:
    Oct 15, 2015
    Messages:
    1,425
    Likes Received:
    233
    Location:
    Berlin, Germany
    When you turn email server functions off, there is a chance, that email server functions might not work. I suggest turning email server functions on for your domain.

    I also second UFHH01. With Office365 and your local mail functionality turned off, you should use the Office365 SMTP gateway to send mail from your domain.
     
  13. Sultansha

    Sultansha New Pleskian

    1
    20%
    Joined:
    Sep 1, 2016
    Messages:
    3
    Likes Received:
    0
    Location:
    Turkey
    We have same problem like author :((
    After upgrading to 12.5.3 phpmail() stopped works. I also had created php test mailscript and it doesn't send mails. And also no any log! Very strange.
    If I access http://mydomain.com/mailtest.php via web - script executes but doesn't send anything anywhere. But if I access this script via ssh like
    #ssh mailtest.php
    it sends mail without any problems.
    I had tried different php versions - same! No logs, no mails. Before upgrading everything worked!
    ----------
    Allow users and scripts to use Sendmail: YES
    Email services are active for the domain: YES
     
  14. Sultansha

    Sultansha New Pleskian

    1
    20%
    Joined:
    Sep 1, 2016
    Messages:
    3
    Likes Received:
    0
    Location:
    Turkey
    Irolan,
    I had the problem that similar to yours and now this issue is solved thanks to professionals from my hosting company. The problem with mail was caused by changed SELinux enforcement mode after Plesk upgrading.
    After Plesk upgrading it become "enforcing" itself so mailscript couldn't access mail service as I could undestand. After change enforcement mode to "permissive" (disable) my mail scripts again works.
    Please try and confirm that you have same problem?
    Regards, Sultansha.
     
  15. Irolan

    Irolan New Pleskian

    1
    70%
    Joined:
    Oct 7, 2015
    Messages:
    9
    Likes Received:
    0
    Sorry for necroing the post. I just wanted to add this in case someone else has the same problem.
    The solution was found by our provider. The problem only occurred when the sites were set to FPM. It worked when set to FastCGI. Something was missing in the FPM installation. They added it, then it worked.
     
  16. UFHH01

    UFHH01 Plesk addicted! Plesk Guru

    43
    64%
    Joined:
    Jun 11, 2013
    Messages:
    5,380
    Likes Received:
    1,163
    Location:
    Hamburg / Germany
    Hi Irolan,

    Thank you very much, for your post, but don't you think it would help much more, if you provide the information(s) WHAT has been changed? At the moment, you are just pushing a thread from Sept. 2016, which may not be relevant at all anymore, due to updates/upgrades and patches. :(
     
Loading...