我可以将 Amazon SES 与 Symfony2 和 Swiftmailer Bundle 一起使用吗?
我在 Amazon 的 ec2 上托管一个网站,运行 64 位版本的 CentOS。
该网站有一个简单的联系我们表单,提交后需要向多个地址发送电子邮件(非常基本)。
有人使用过带有 Symfony2 和 Swiftmailer Bundle 的 Amazon SES 吗?如果是这样,您是否建议使用 SES 或更传统的电子邮件服务器来执行此类任务?
I'm hosting a site on Amazon's ec2 running a 64-bit version of CentOS.
The site has a simple Contact Us form that needs to send an email to several addresses when submitted (pretty basic).
Has anyone used Amazon's SES with Symfony2 and the Swiftmailer Bundle? And if so, do you recommend using SES or a more traditional email server for this type of task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
可以使用 swiftmailer 库附带的本机 SMTP 传输通过 SES 发送电子邮件。以下示例使用版本 4.2.2 进行测试。
Amazon SES 需要使用 TLS 加密。
通过传递 tls 作为第三个构造函数参数,可以将 Swift_SmtpTransport 传输类配置为使用 TLS 加密:
在 Symfony2 中,您可以将 swiftmailer 服务配置为使用 TLS 加密:
直接从 EC2 实例上安装的邮件服务器发送电子邮件不太可靠,因为 EC2 IP 地址可能已列入黑名单。建议使用受信任的邮件服务器,因此使用 SES 似乎是一个好主意。
It is possible to send email via SES with the native SMTP transport shipped with the swiftmailer library. Examples below were tested using version 4.2.2.
Amazon SES requires usage of TLS encryption.
Swift_SmtpTransport
transport class can be configured to use TLS encryption by passing tls as the third constructor argument:In Symfony2, you can configure the
swiftmailer
service to use TLS encryption:Sending emails directly from a mailserver installed on an EC2 instance is not very reliable as EC2 IP addresses may be blacklisted. It is recommended to use a trusted mailserver so using SES seems to be a good idea.
通过 Symfony2 通过 SES 发送邮件对我来说并不是开箱即用的,因为我在 config.yml 中配置了假脱机选项。
我偶然发现的另一个问题是端口。端口 25 和 587 工作完美,但 465 让我超时。
使用正确的 SMTP 服务器非常重要,起初我使用的是 us-east-1 (因为我从示例中复制了它),尽管我的 SMTP 实际上是 email-smtp.eu-west-1.amazonaws.com
所以这是我当前的配置:
我通过在命令行上执行以下命令发现了问题:
Sending mails through SES via Symfony2 didn't work out of the box for me because I had the spool option configured in my config.yml.
Another problem I stumbled upon was the port. Port 25 and 587 work perfect but 465 got me a timeout.
And it's important that you are using the right SMTP server, at first I was using us-east-1 (because I copied it from an example) although my SMTP actually was email-smtp.eu-west-1.amazonaws.com
So here's my current config:
I found the problem by executing the following on my command line:
有一个为 swiftmailer 预先构建的 SES 传输。设置非常容易:
https://github.com/jmhobbs/Swiftmailer-Transport- -AWS-SES
There's an SES transport prebuilt for swiftmailer. Very easy to set up:
https://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES
如果您可以坚持免费套餐限制(每日 2K 条消息),我绝对建议您坚持使用 SES 而不是传统的电子邮件服务器。它简单、易于与大多数平台集成,并且您可以消除电子邮件服务器的维护和运营成本(虽然很小,但它们仍然存在)。当然,使用 SES 时仍然存在数据传输费用,如您在 Amazon SES 定价,但这也可能适合您的需求。
If you can stick with the free tier limits (2K daily messages), I'd definitely recommend you to stick with SES instead of a traditional email server. It's simple, easy to integrate with most platforms, and you eliminate the maintenance and operation costs (although small, they are still there) for your email server. Of course, there are still data transfer costs when using SES, as you can see on Amazon SES pricing, but that might fit your needs as well.
自 2011 年 12 月起,您可以将 smtp 与 switfmail 一起使用,但在此之前问题是该捆绑包仍然没有通过 EC2 工作的实现,但已经存在。如果您喜欢使用 switfmail 等框架发送电子邮件,您应该拥有密码和密钥,然后执行以下操作:
要获取密钥,请进入 AWS 管理控制台”>“SMTP 设置”>“创建我的 SMTP 凭证
”需要安装此扩展:
https://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES
但我重复一遍这只是信息现在,您应该先在 AWS 管理控制台中验证您的电子邮件帐户。稍后应该可以工作。
Since december 2011 you can use smtp with switfmail but before The problem was that this bundle still don't have the implementation for work over EC2, but already exists. If you like send emails with some framework like switfmail you should have your password and key, and do something like this:
For take your key go inside AWS Management Console" > "SMTP Settings" > "create my SMTP credentials"
And you are going to need install this extension :
https://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES
but I repet this is only information. Now, you should verified your email account before in your AWS Management Console and later should work.
在较新的 Symfony 版本中,包含了对 SES 的支持。您只需传递您的凭据并在配置中设置您的 stmp 主机即可。
请参阅 Symfony 3.4 和 Symfony 4.X
On more recent Symfony versions, support for SES is included. You can simply pass your credentials and set your stmp host in configuration.
See documentation for Symfony 3.4 and for Symfony 4.X
只需添加“tls”作为第三个参数即可。工作正常
前任:
Just add 'tls' as third paramater. Works fine
Ex: