Question

How to use Amazon SES key, secret + smtp address in my Zend_Mail_Transport_Smtp ? It says: Must issue a STARTTLS command first while trying following.

  /*
    Reference in C#: http://sesblog.amazon.com/

    String username = "SMTP-USERNAME";  // Replace with your SMTP username.
    String password = "SMTP-PASSWORD";  // Replace with your SMTP password.
    String host = "email-smtp.us-east-1.amazonaws.com";
    int port = 25;

  */
  public static function sendEmail($to, $subject, $body) {
    $config = array(
        'aws_key' => 'yourkey',
        'aws_secret' => 'yourkeysecret',
    ));

    //
    //echo 0 > /selinux/enforce
    //$tr = new Zend_Mail_Transport_Smtp('smtp.belgacom.be');// works - for local
    //$tr = new Zend_Mail_Transport_Smtp('out.telenet.be' ); // works - for office
    //
    $tr = new Zend_Mail_Transport_Smtp(
                      'email-smtp.us-east-1.amazonaws.com'); // DOES not work
    Zend_Mail::setDefaultTransport($tr);

    $mail = new Zend_Mail();
    $html = self::setupEmail($body);
    $mail->setBodyHtml($html); 
    $mail->setFrom('support@memy.com', 'memy.com');
    $mail->addTo($to, 'EXAMPLE');
    $mail->setSubject($subject);
    $mail->send();
  }

Follow up:

// Wild guess
$config = array(
  'aws_key' => 'yourkey',
  'aws_secret' => 'yourkeysecret',
));
$tr = new Zend_Mail_Transport_Smtp('email-smtp.us-east-1.amazonaws.com', 
                                   $config);

Final follow up:

Step 1) To send email using the Amazon SES SMTP interface, you will need the following:

  • An AWS account.

  • Amazon SES production access, if you want to send large quantities of email. For more information, see Requesting Production Access.

    -- after doing it, they allow send 10000 emails per 24 hour period

    -- this is quickly activated like less then 24 hour

    -- 5 emails/second

  • An email address that you have verified with Amazon SES. For more information, see Verifying Email Addresses.

    -- this takes while to validate by them

    -- this is still after 24 hour not yet confirmed

  • The SMTP interface hostname and port number. The hostname is email-smtp.us-east-1.amazonaws.com. The port number varies with the connection method. For more information, see Connecting to the SMTP Endpoint.

    -- very important else, it was failing

  • An SMTP user name and password that you obtain from the AWS Management Console. For more information, see SMTP Credentials.

  • Client software that can communicate using TLS (Transport Layer Security).

Step 2) I have done above those, in there management console it shows:

Status:
pending verification (resend)
Please check your inbox for an email to this address, and click on the link provided to complete verification. If you did not receive this email, please click resend.

Domain verification in AWS:

Status:
pending verification (resend)
Please check your inbox for an email to this address, and click on the link provided to complete verification. If you did not receive this email, please click resend.

which means, they will do something within 72 hours

Step 3) Modify the $config without using external Adapters (not shifted by ZF)

$config = array(
  'auth' => 'login',
  'username' => 'SES key',
  'password' => 'SES secret',
));
$tr = new Zend_Mail_Transport_Smtp('email-smtp.us-east-1.amazonaws.com', 
                                   $config);
Was it helpful?

Solution

I guess the easiest way is to go with this add-in: Amazon-SES-Zend-Mail-Transport. On the other hand you can write it yourself if you dig yourself through the Zend_Mail_Transport.

EDIT

Response: 530 Must issue a STARTTLS command first means that you need to enable a secure connection before you authenticate.

Please also make sure you are using the SES SMTP credentials when connecting via SMTP. These credentials are different from your AWS credentials. From the code you posted, it appears you may be using the AWS credentials.

And check the Readme provided on github ;)

EDIT 2

Try adding this to your config:

$config = array('ssl' => 'tls','port' => 25);

EDIT 3

554 Message rejected: Email address is not verified appears even the address was verified. Some ideas why it's not working:

1.) The verified addresses are case sensitive, so if you are using it in a different case than what you verified, you will run into problems. This comes down to strict interpretation of the rfc. -> check this

2.) I think Amazon dont like role based addresses like admin@yourdomain.com -> check this

OTHER TIPS

I was getting '554 Message rejected: Email address is not verified', but an edit to /etc/php.ini fixed it for me:

sendmail_path = /usr/sbin/sendmail -t -i -f someone@yourdomain.com

Credit: http://www.petermac.com/php-mail-function-with-postfix/

Another follow up.

In the interest of helping others with the same problem, here is the exact procedure I have recently used to get this working correctly.

Use this first of all https://github.com/christophervalles/Amazon-SES-Zend-Mail-Transport

And then this :

$mail = new Zend_Mail('utf-8');
$transport = new App_Mail_Transport_AmazonSES(
    array(
       'accessKey' => 'YOUR_ACCESS_KEY',
       'privateKey' => 'YOUR_PRIVATE_KEY'
    )
);
$mail->addTo('destination@example.com', 'Recipient')
    ->setFrom('your.verified.email@gmail.com', 'Webmaster')
    ->setSubject('Email subject line')
    ->setBodyText('Email body')
    ->send($transport);

For more details and possible errors : http://shakyshane.com/blog/amazon_ses_zend_framework.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top