The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

localhost gives dovecot authenticator error using trying to auth smtp to external server

Discussion in 'E-mail Discussions' started by FirstMM, Mar 28, 2014.

  1. FirstMM

    FirstMM Member

    Joined:
    Sep 21, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hi all,

    I am not familiar with the cPanel set up so I am hoping someone can help me get this resolved.

    I have a test PHP script which sends an email using Mail::factory and SMTP AUTH on port 465 to an external SMTP server.

    If I "php mailertest.php" as root on the server then the email sends fine and there is (as expected) no hit on the mail log.

    If, however, I try to run the same script via a webpage or as the cPanel user then I get the following in the maillog:

    dovecot_login authenticator failed for <hostname> (localhost) <IP: port> 535 Incorrect authentication data (set_id=<emailaddress>)
    SMTP connection from <hostname> (localhost) <IP: port> closed by QUIT


    It appears that the server is attempting to use POP before SMTP on the localhost and thus failing to send.
    The domain name has been removed from /etc/localdomains and added to /etc/remotedomains already and is correctly configured on the remote SMTP mail server.

    Can someone please tell me what needs to be reconfigured?
    Thanks!
     
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,447
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    The code in your script is probably what's in need of some attention. This isn't a cPanel issue, it's an issue with your script.
     
  3. FirstMM

    FirstMM Member

    Joined:
    Sep 21, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for taking the time to reply Infopro :)

    The code works fine when run as root from the server which is why I am confused!
    Why would it run correctly as root (i.e. hit the remote server directly and correctly) and yet hit the local server POP before SMTP when run as the domain user if it is an error in the code?

    In order to 100% guarantee that the code is not at fault (I took your suggestion seriously), I added it to another non cPanel server and it ran fine from there (not running as root but as a standard user).
     
  4. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,447
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    No way of knowing without seeing the script I don't think.
     
  5. FirstMM

    FirstMM Member

    Joined:
    Sep 21, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    lol if it will make you happy the code comes from the following URL:
    How to Send Email from a PHP Script Using SMTP Authentication (and SSL Encryption) - About Email, 2nd example.
    Obviously I have already substituted the email addresses and SMTP server with real ones and not just pasted this into a shell window as is.

    Shell output from cPanel server:
    Code:
    #runuser -l root -c 'php /home/testuser/mailer.php'
    #[I]<p>Message successfully sent!</p>[/I]
    
    runuser -l testuser -c 'php /home/testuser/mailer.php'
    <p> authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)]</p>
    Shell output from non cPanel server:
    Code:
    #runuser -l root -c 'php /home/testuser/mailer.php'
    #[I]<p>Message successfully sent!</p>[/I]
    
    runuser -l testuser -c 'php /home/testuser/mailer.php'
    <p>Message successfully sent!</p>

    mailer.php
    PHP:
    <?php
     
    require_once "Mail.php";
     
     
    $from "Sandra Sender <sender@example.com>";
     
    $to "Ramona Recipient <recipient@example.com>";
     
    $subject "Hi!";
     
    $body "Hi,\n\nHow are you?";
     
     
    $host "ssl://mail.example.com";
     
    $port "465";
     
    $username "smtp_username";
     
    $password "smtp_password";
     
     
    $headers = array ('From' => $from,
       
    'To' => $to,
       
    'Subject' => $subject);
     
    $smtp Mail::factory('smtp',
       array (
    'host' => $host,
         
    'port' => $port,
         
    'auth' => true,
         
    'username' => $username,
         
    'password' => $password));
     
     
    $mail $smtp->send($to$headers$body);
     
     if (
    PEAR::isError($mail)) {
       echo(
    "<p>" $mail->getMessage() . "</p>");
      } else {
       echo(
    "<p>Message successfully sent!</p>");
      }
     
    ?>
     
  6. FirstMM

    FirstMM Member

    Joined:
    Sep 21, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Just a quick bump. Has anyone else come across this before and found a solution?
     
Loading...

Share This Page