Ruby-on-rails 从 AWS EC2 实例发送电子邮件(必须使用 SES?)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23829141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send emails from AWS EC2 instance (SES mandatory?)
提问by Rober
I write this post just to see if I can get some clarifications regarding email sending concepts in an AWS EC2 instance.
我写这篇文章只是想看看我是否能得到一些关于 AWS EC2 实例中电子邮件发送概念的说明。
This is related with this other post Rails does not send emails on AWS
这与另一篇文章Rails 不会在 AWS 上发送电子邮件有关
I′m developing a Rails application that sends emails to customers (such as confirmation or information emails).
我正在开发一个向客户发送电子邮件的 Rails 应用程序(例如确认或信息电子邮件)。
I dont know exactly which email service is using Rails. I didn′t install any particular gem. But the emails are been sent perfectly in development environment (Ubuntu).
我不确切知道哪个电子邮件服务正在使用 Rails。我没有安装任何特定的 gem。但是电子邮件在开发环境(Ubuntu)中发送完美。
When I deploy to my production environment (AWS EC2 instance). This functionality is not working. You can see the error details in the post I provided above. The error is related with some smtp connection refused.
当我部署到我的生产环境(AWS EC2 实例)时。此功能不起作用。您可以在我上面提供的帖子中查看错误详细信息。该错误与某些smtp connection refused.
So, I have read some other posts but Im confused. Is it mandatory to use the AWS SES service in order to send emails from EC2 instance? Or it is just a problem related to security credentials (maybe I just need to open the smtp 25 port). Do I need to install any email client or server?
所以,我读了一些其他的帖子,但我很困惑。是否必须使用 AWS SES 服务才能从 EC2 实例发送电子邮件?或者它只是与安全凭证相关的问题(也许我只需要打开 smtp 25 端口)。我需要安装任何电子邮件客户端或服务器吗?
回答by Sébastien Stormacq
Sending emails from EC2 instances is limited by Amazon and strictly throttled at network level. This is to prevent spamming and other abuses.
从 EC2 实例发送电子邮件受到 Amazon 的限制,并在网络级别受到严格限制。这是为了防止垃圾邮件和其他滥用行为。
If you have a large amount of emails to send to your customers, the recommended way is to use Amazon Simple Email Service. With Amazon SES, you can send transactional email, marketing messages, or any other type of high-quality content and you only pay for what you use.
如果您要向客户发送大量电子邮件,推荐的方法是使用Amazon Simple Email Service。借助 Amazon SES,您可以发送交易电子邮件、营销信息或任何其他类型的高质量内容,并且只需为使用的内容付费。
If you really need to send emails from an EC2 instance, you must use an Elastic IP Adress and ask Amazon's support to remove limitations on SMTP traffic from that EIP. The form to contact us is available at https://portal.aws.amazon.com/gp/aws/html-forms-controller/contactus/ec2-email-limit-rdns-request(authentication is required)
如果您确实需要从 EC2 实例发送电子邮件,则必须使用弹性 IP 地址并请求 Amazon 的支持人员取消对来自该 EIP 的 SMTP 流量的限制。联系我们的表格可在https://portal.aws.amazon.com/gp/aws/html-forms-controller/contactus/ec2-email-limit-rdns-request(需要身份验证)
Seb
塞伯
回答by Pedro
As sebasto wrote, sending emails is limited.
正如 sebasto 所写,发送电子邮件是有限的。
https://aws.amazon.com/ec2/faqs/=> Q: Are there any limitations in sending email from EC2 instances?
https://aws.amazon.com/ec2/faqs/=> 问:从 EC2 实例发送电子邮件是否有任何限制?
Of course it's working, you need to check if you have SMTP installed and it might depends when do you send your's emails
当然它可以工作,您需要检查是否安装了 SMTP,这可能取决于您何时发送电子邮件
Try this code:
试试这个代码:
[ec2-user@ip ~]$ irb
irb(main):001:0> require 'net/smtp'
=> true
irb(main):002:0> Net::SMTP.start('localhost') do |smtp|
irb(main):003:1* smtp.send_message 'test from ruby', 'your-email, 'your-email'
irb(main):004:1> end
For mine (@gmail) it's working
对于我的(@gmail)它正在工作

