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.

Allow single account PHP direct email relaying

Discussion in 'E-mail Discussions' started by aralis, Feb 3, 2016.

  1. aralis

    aralis Member

    Joined:
    Dec 22, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Lubbock TX
    Hello, I'm writing this post as a last resource as I truely cannot figure out my next move.

    My goal is to use the PHP swiftmailer class to send email through AWS SES on a single account on my WHM server, it has been working fine before on port 2587 with TLS encryption but a recently cpanel update seems to have blocked this (as it rightly should from a security perspective).

    I have tried disabling both options in WHM:
    Server Settings -> Tweak Settings ->
    Prevent “nobody” from sending mail [?] = off
    Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) [?] = off​

    The script works if executed as root, but does not work if executed by the account:
    Code:
    [root:fire] /home/dawn777/public_html/old/automation/include # php -f swtest.php 
    Message send results: 1
    
    dawn777@dawnet.net [~/public_html/old/automation/include]# php -f swtest.php 
    
    Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host email-smtp.us-west-2.amazonaws.com [Connection refused #111]' in /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Transport/StreamBuffer.php:266
    Stack trace:
    #0 /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Transport/StreamBuffer.php(64): Swift_Transport_StreamBuffer->_establishSocketConnection()
    #1 /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array)
    #2 /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start()
    #3 /home/dawn777/public_html/old/automation/include/swtest.php(34): Swift_Mailer->send(Object(Swift_Message))
    #4 {main}
      thrown in /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Transport/StreamBuffer.php on line 266
    


    Here is the script:
    Code:
    <?
    $SMTPhost   = "email-smtp.us-west-2.amazonaws.com";
    $SMTPuser   = "foo";
    $SMTPpass   = "bar";
    $SMTPport   = '2587';
    $SMTPenc    = 'tls';
    
    
      // echo stream_get_transports();
    
      require_once 'swift/lib/swift_required.php';
    
      // Create the Transport
      $transport = Swift_SmtpTransport::newInstance($SMTPhost, $SMTPport, $SMTPenc)
        ->setUsername($SMTPuser)
        ->setPassword($SMTPpass)
        ;
    
     // Create the Mailer using your created Transport
      $mailer = Swift_Mailer::newInstance($transport);
    
      // Create a message
      $message = Swift_Message::newInstance('Wonderful Subject')
        ->setFrom('support@foo.net')
        ->setTo(array('test@bar.com'))
        ->setBody('Here is the message itself')
        ;
    
      // Send the message
      $result = $mailer->send($message);
      echo "Message send results: $result";
    
    
    ?>
    
    
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Could you let us know which version of PHP is installed on this system? Have you reported the issue to the developers of the script?

    Thank you.
     
  3. aralis

    aralis Member

    Joined:
    Dec 22, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Lubbock TX
    PHP Version 5.3.27
    You can see full details here:
    - Removed -

    I have not reached out to the script provider as I have tried this same script on several different non-cpanel systems and it works fine. I will also not that in the past, it would not work on the cPanel system on standard SMTP ports with TLS or SSL encryption. The only way that I was able to get it working was to use the one nonstandard port that Amazon allows which is 2587. That solution was fine until cPanel patched it.
     
    #3 aralis, Feb 4, 2016
    Last edited by a moderator: Feb 4, 2016
  4. aralis

    aralis Member

    Joined:
    Dec 22, 2006
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Lubbock TX
    Okay you can disregard. I was unable to resolve the issue but I did find a workaround which is probably the appropriate way to do it in the first place.

    For reference for anyone with a similar issue, I added the following to the Exim config (through WHM I might add) to make the system MTA (exim) be in charge of the connection SES and I am using the swift class to pass the email along to the MTA.

    Code:
    !ROUTERS
    send_via_ses:
    driver = manualroute
    domains = ! +local_domains
    senders = foo@bar.com
    transport = ses_smtp
    route_list = * email-smtp.us-west-2.amazonaws.com;
    
    !TRANSPORT BEGIN
    ses_smtp:
    driver = smtp
    port = 587
    hosts_require_auth = $host_address
    hosts_require_tls = $host_address
    
    
    !AUTHENTICATION
    ses_login:
    driver = plaintext
    public_name = LOGIN
    client_send = : USERNAME : PASSWORD
    
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page