【问题标题】:How to use Amazon SES key, secret + smtp address in my Zend_Mail_Transport_Smtp adapter?如何在我的 Zend_Mail_Transport_Smtp 适配器中使用 Amazon SES 密钥、密钥 + smtp 地址?
【发布时间】:2012-06-18 08:16:37
【问题描述】:

如何在我的Zend_Mail_Transport_Smtp 中使用 Amazon SES 密钥、密钥 + smtp 地址? 它说: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();
  }

跟进:

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

最终跟进:

步骤 1) 要使用 Amazon SES SMTP 接口发送电子邮件,您将需要以下内容:

  • 一个 AWS 账户。

  • Amazon SES 生产访问,如果您想发送大量电子邮件。有关详细信息,请参阅请求生产访问权限。

    -- 完成后,他们允许send 10000 emails per 24 hour period

    -- 不到 24 小时就可以快速激活

    -- 5 封电子邮件/秒

  • 您已通过 Amazon SES 验证的电子邮件地址。有关详细信息,请参阅验证电子邮件地址。

    -- 这需要一段时间才能被他们验证

    -- 24 小时后仍未确认

  • SMTP 接口主机名和端口号。主机名是 email-smtp.us-east-1.amazonaws.com。端口号因连接方法而异。有关详细信息,请参阅连接到 SMTP 端点。

    -- 其他很重要,它失败了

  • 您从 AWS 管理控制台获取的 SMTP 用户名和密码。有关详细信息,请参阅 SMTP 凭据。

  • 可以使用 TLS(传输层安全)进行通信的客户端软件。

第 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.

也就是说,他们会在 72 小时内做某事

第 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);

【问题讨论】:

    标签: php zend-framework amazon-ec2 zend-mail amazon-ses


    【解决方案1】:

    另一个跟进。

    为了帮助其他人解决同样的问题,这是我最近用来使其正常工作的确切过程。

    首先使用这个https://github.com/christophervalles/Amazon-SES-Zend-Mail-Transport

    然后这个:

    $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);
    

    有关更多详细信息和可能的错误: http://shakyshane.com/blog/amazon_ses_zend_framework.html

    【讨论】:

    • 请注意,这里不鼓励裸链接到您自己的网站/产品,原因有两个;首先,答案应该作为独立的答案发布,而不仅仅是指向外部站点的链接。其次,在这里自我推销往往不受欢迎,并且经常被标记为垃圾邮件(特别是如果没有披露您链接到自己的网站/产品)。
    • 同样的事情你在ZF2中怎么做?
    【解决方案2】:

    我收到“554 消息被拒绝:电子邮件地址未验证”,但对 /etc/php.ini 的编辑为我修复了它:

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

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

    【讨论】:

    • 同样的事情你在ZF2中怎么做?
    【解决方案3】:

    我想最简单的方法是使用这个插件:Amazon-SES-Zend-Mail-Transport。另一方面,如果您通过 Zend_Mail_Transport 挖掘自己,则可以自己编写。

    编辑

    Response: 530 Must issue a STARTTLS command first 表示您需要在进行身份验证之前启用安全连接。

    还请确保您在通过 SMTP 连接时使用的是 SES SMTP credentials。这些凭证不同于您的 AWS 凭证。从您发布的代码来看,您可能正在使用 AWS 凭证。

    并查看 github 上提供的自述文件 ;)

    编辑 2

    尝试将此添加到您的配置中:

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

    编辑 3

    554 Message rejected: Email address is not verified 即使地址已经过验证也会出现。为什么它不起作用的一些想法:

    1.) 已验证的地址区分大小写,因此如果您在与您验证的地址不同的情况下使用它,则会遇到问题。这归结为对 rfc 的严格解释。 ->检查一下

    2.) 我认为亚马逊不喜欢像 admin@yourdomain.com 这样的基于角色的地址->检查一下

    【讨论】:

    • “它不工作”有点含糊;)发生的确切错误是什么?
    • 1) 我已经完成了 docs.amazonwebservices.com/ses/latest/DeveloperGuide/… 中提到的所有这些操作 2) 我现在从开始使用 SES SMTP 凭证(不是 AWS 凭证 3)仍然给出 530 4)这是否意味着,有技术人员必须手动为我的帐户修改某些内容,然后它将被激活??
    • 4 -> 不明白你的意思,也许你有什么不对劲我不知道……
    • 是的,最后一次编辑确实做了一些事情。但它仍然显示Message rejected: Email address is not verified(请参阅我的评论,我确实使用 Amazon SES 程序验证了电子邮件)
    • 谢谢。仍然没有完全工作,但身份验证正常 + 电子邮件无效,这可能是我上面最后一次编辑的相关问题。
    猜你喜欢
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 2020-12-01
    • 1970-01-01
    相关资源
    最近更新 更多