aws WorkMail和SES实战
需求:
1. 在web server的PHP代码中,发送注册邮件;
2. 客服邮箱。
WorkMail 和 SES 的关系
Amazon WorkMail uses Amazon SES to send and receive mail. When you set up Amazon WorkMail, Amazon WorkMail creates two items within your Amazon SES configuration settings: a sending authorization policy that allows Amazon WorkMail to send mail through your domain, and a receipt rule with a WorkMail action that delivers your domain’s incoming mail to Amazon WorkMail. If you remove either of these items, Amazon WorkMail will not function properly.
配置WorkMail
- 创建Organization
easyrote - 配置Domain
默认会添加这个:easyrote.awsapps.com
再添加一个: easyrote.jp // Set as Default
配置easyrote.jp时,会出现一堆DNS 配置: TXT, MX, CNAME 等等。 都添加到DNS服务器上,不要漏了autodiscover.easyrote.jp,否则outlook找不到它。
如果DNS server使用的是aws的Route53,这些DNS信息都会自动添加到Route53中,不需要手动配置。
如果使用的是其它DNS服务,添加配置之后,需要等一段时间(几个小时,也许更长),DNS才会生效。
在配置WorkMail时,aws会自动在SES中创建相应的domain。 - 创建邮件帐户
WorkMail按邮件帐户收费,每个帐户每月4$
我们只需要两个,一个是 [email protected],在webservice中使用,用于发送注册邮件、找回密码等等。 一个是[email protected],用于客服。
好了,至此,WorkMail配置完毕,可以使用我们的邮箱了。
在网页上访问邮箱
地址:easyrote.awsapps.com/mail
输入用户名、密码登录,如[email protected],用户名是 support
配置邮件客户端 outlook
-
Windows10
打开outlook,添加帐户
勾选 “让我手动设置我的账户”
选择Exchange。 等待,可能需要几分钟。
成功了。 Mac
输入邮件地址
点击 Not IMAP
选择Exchange
注意,DOMAIN\username or Email 那一行,要输入完整的邮件地址。
勾选 Always use my response for this server,点击 Allow
迁移[email protected] 历史邮件
https://aws.amazon.com/workmail/details/
在这个页面中找到 Migrate to Amazon WorkMail for Free,这一段讲到了两个工具 audriga 和 Transend,可以免费迁移邮箱。
打开 audirga 的workmail迁移页面: https://workmail.audriga.com/,向下滚动,找到 Full migration,点击start now,它会让你填写一些信息,发起一个migration request。 过一会儿,会收到答复邮件。按照答复邮件中的指示一步步执行就可以了。迁移的过程比较慢,7000多封邮件125M,用了一个多小时。
在PHP代码中发送邮件
在SES中配置bounces和complaints notification
邮件被弹回、拒收、报告垃圾邮件时,如何处理。
SES -> Domain -> easyrote.jp -> Notification -> Edit Configuration
创建一个SNS Topic(发送报告的一个指定的邮箱),让它们都指向这个topic就可以了。创建一个Case, 请求aws提升发件limit
https://console.aws.amazon.com/support/home?region=us-east-1#/case/create
默认情况下,我们的SES配置处于sandbox中,只能使用验证过的邮件地址发送邮件,每天限制200封。
这个case通过之后,才能正常使用SES发送邮件。bounces和complaints一定要处理,否则,case通不过。在SES中配置 smtp credential
两大串乱七八糟的字符,作为用户名和密码,PHPMailer对象的Username和Password。-
使用SES发送邮件
aws官方代码示例,C#、Java、PHP都有:
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-programmatically.html
代码有点旧了,以下两行需要修改,否则,连不上服务器。mail−>SMTPSecure=‘ssl′;//改成tls mail->Port = 465; // 改成 25 或者 587选择发件服务器:
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html#region-endpoints部分代码:
mail−>Host=‘email−smtp.us−east−1.amazonaws.com′; mail->SMTPAuth = true;mail−>Username=‘在SES中创建的smtpcredentialusername′; mail->Password = ‘在SES中创建的smtp credential password’;mail−>SMTPDebug=3; mail->SMTPSecure = ‘tls’;mail−>Port=587; mail->setFrom(‘[email protected]’, ‘Easyrote Japan’); -
配置ssl(我用的是ec2,CentOS)
yum install openssl*
重新编译php
./configure –prefix=/usr/local/webserver/php –with-libdir=lib64 –with-config-file-path=/usr/local/webserver/php/etc –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm -enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl=shared –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap
curl -s https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt | patch -p0
make
make install
编辑php.ini, 加上 extension=openssl.so重启php-fpm, 重启nginx
killall php-fpm
nginx -s restart在命令行下可以了。但web服务不行,注册邮件不能发送。
在命令行输出phpinfo()
php -r “phpinfo();”
ssl, tls 都有。在web页面上打印 phpinfo()
ssl, tls 都没有,而自己开发用的虚拟机上有。重新启动 php-fpm, 居然可以了。