简体   繁体   English

如何在Zend_Mail_Transport_Smtp适配器中使用Amazon SES密钥,机密+ smtp地址?

[英]How to use Amazon SES key, secret + smtp address in my Zend_Mail_Transport_Smtp adapter?

How to use Amazon SES key, secret + smtp address in my Zend_Mail_Transport_Smtp ? 如何在Zend_Mail_Transport_Smtp使用Amazon SES密钥,机密+ SMTP地址? It says: Must issue a STARTTLS command first while trying following. 它说:在尝试跟随时Must issue a STARTTLS command first

  /*
    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: 步骤1)要使用Amazon SES SMTP界面发送电子邮件,您将需要以下内容:

  • An AWS account. 一个AWS账户。

  • Amazon SES production access, if you want to send large quantities of email. 如果要发送大量电子邮件,请使用Amazon SES生产访问权限。 For more information, see Requesting Production Access. 有关更多信息,请参见请求生产访问。

    -- after doing it, they allow send 10000 emails per 24 hour period -完成后,他们允许send 10000 emails per 24 hour period

    -- this is quickly activated like less then 24 hour -不到24小时即可快速激活

    -- 5 emails/second -每秒5封电子邮件

  • An email address that you have verified with Amazon SES. 您已使用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 -24小时后仍未确认

  • The SMTP interface hostname and port number. SMTP接口主机名和端口号。 The hostname is email-smtp.us-east-1.amazonaws.com. 主机名是email-smtp.us-east-1.amazonaws.com。 The port number varies with the connection method. 端口号因连接方法而异。 For more information, see Connecting to the SMTP Endpoint. 有关更多信息,请参见连接到SMTP端点。

    -- very important else, it was failing -非常重要的是,它失败了

  • An SMTP user name and password that you obtain from the AWS Management Console. 您从AWS管理控制台获取的SMTP用户名和密码。 For more information, see SMTP Credentials. 有关更多信息,请参阅SMTP凭据。

  • Client software that can communicate using TLS (Transport Layer Security). 可以使用TLS(传输层安全性)进行通信的客户端软件。

Step 2) I have done above those, in there management console it shows: 步骤2)我已经完成了以上操作,在该控制台中显示:

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 这意味着他们将在72小时内完成某件事

Step 3) Modify the $config without using external Adapters (not shifted by ZF) 步骤3)在不使用外部适配器的情况下修改$ config(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);

I guess the easiest way is to go with this add-in: Amazon-SES-Zend-Mail-Transport . 我猜最简单的方法是使用此插件: Amazon-SES-Zend-Mail-Transport On the other hand you can write it yourself if you dig yourself through the Zend_Mail_Transport. 另一方面,如果您通过Zend_Mail_Transport进行挖掘,则可以自己编写。

EDIT 编辑

Response: 530 Must issue a STARTTLS command first means that you need to enable a secure connection before you authenticate. Response: 530 Must issue a STARTTLS command first ,这意味着您需要在身份验证之前启用安全连接。

Please also make sure you are using the SES SMTP credentials when connecting via SMTP. 通过SMTP连接时,还请确保您正在使用SES SMTP凭据 These credentials are different from your AWS credentials. 这些凭证与您的AWS凭证不同。 From the code you posted, it appears you may be using the AWS credentials. 从您发布的代码来看,您似乎正在使用AWS凭证。

And check the Readme provided on github ;) 并检查github提供的自述文件;)

EDIT 2 编辑2

Try adding this to your config: 尝试将其添加到您的配置中:

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

EDIT 3 编辑3

554 Message rejected: Email address is not verified appears even the address was verified. 554 Message rejected: Email address is not verified即使地址已验证, 554 Message rejected: Email address is not 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. 1.)验证后的地址区分大小写,因此,如果您使用的地址与验证后的地址不同,则将遇到问题。 This comes down to strict interpretation of the rfc. 这归结为对RFC的严格解释。 -> check this ->检查这个

2.) I think Amazon dont like role based addresses like admin@yourdomain.com -> check this 2.)我认为亚马逊不喜欢基于角色的地址,例如admin@yourdomain.com- >选中此选项

I was getting '554 Message rejected: Email address is not verified', but an edit to /etc/php.ini fixed it for me: 我收到“ 554邮件被拒绝:电子邮件地址未验证”,但是对/etc/php.ini的修改为我修复了此问题:

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

Credit: http://www.petermac.com/php-mail-function-with-postfix/ 图片来源: 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 首先使用此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 有关更多详细信息和可能的错误: http : //shakyshane.com/blog/amazon_ses_zend_framework.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM