问题描述
我使用Rails 4.2的 AWS-SES宝石和的。我试图建立AWS SES在开发和已经加入这个配置/ development.rb
:
I am using Rails 4.2, the AWS-SES gem and the Mailform gem. I am trying to set up AWS SES in development and have added this to config/development.rb
:
# Configure mail using AWS SES
config.after_initialize do
ActionMailer::Base.delivery_method = :amazon_ses
ActionMailer::Base.custom_amazon_ses_mailer = AWS::SES::Base.new(
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
:access_key_id => ENV['AWS_SECRET_KEY_ID'],
:server => 'email.eu-west-2.amazonaws.com'
)
end
当我试图从控制台发送电子邮件,我30秒后得到一个超时。我开始写这一切了寻求帮助,但它发生,我认为 MailForm
可能无法从的ActionMailer
。果不其然, MailForm :: Base的
有超对象
,所以配置的ActionMailer
是没有意义的。
When I attempt to send emails from the console, I am getting a timeout after 30 seconds. I started to write all this up asking for help, but then it occurred to me that MailForm
may not be derived from ActionMailer
. Sure enough, MailForm::Base
has superclass Object
, so configuring ActionMailer
is pointless.
我改变了这两条线配置 MailForm :: Base的
,但我仍然获得了超时。难道这两种宝石是不兼容?否则,任何建议,要么解决或解决将AP preciated。
I changed these two lines to configure MailForm::Base
, but I still get a timeout. Is it possible that these two gems are not compatible? Otherwise, any suggestions to either resolve or troubleshoot would be appreciated.
推荐答案
正如我在我的问题提到的, MailForm
和 AWS-SES
宝石是不兼容的开箱即用。这是可能的,他们可以向一起工作,但我采取了不同的路线。
As I mentioned in my question, the MailForm
and AWS-SES
gems are not compatible out of the box. It is possible that they can be made to work together but I took a different route.
某些键设置 AWS-SES
(code包括如下,仅供参考):
Some keys to setting up AWS-SES
(code included below for reference):
- 在AWS设置 - 与AWS您在沙盒模式开始。您需要注册所有在SES控制台目的地的电子邮件地址的任何工作。点击
电子邮件地址
链接列出您的验证地址,并添加更多。此外,您将需要设置AWS IAM
凭证创业板来使用。执行此操作时,确保用户拥有连接(在IAM控制台上)的SES完全访问管理的策略。 -
:服务器
设置 - 自动气象站工作在多个地区,但您的SES的帐户将被设立在其中的一个。要确定您所在的地区,到AWS控制台,然后单击SES。您将看到您所在地区的URL - 对我来说是地区= US-西2
。在丹呱 - 呱的描述我建议设立一个初始化优秀的文章。我之所以这样做是因为丹建议,除了我设置的传送方法:亚马逊SES
并添加一台服务器配置行 - 配置 - 丹的文章(上述)介绍如何设置
delivery_method
环境中的配置文件。再有,我用:亚马逊SES
- 一旦AWS配置和安装你的宝石,你可以测试在轨控制台您的设置。更容易解决比出现在code碱基。
- 有点风马牛不相及,但我用了
Dotenv
宝石来管理我的环境设置。概括地说,一旦你安装了宝石,你可以坚持所有的环境设置,〜/ .ENV
并有机会获得他们ENV
整个code。
- AWS set up - with AWS you start off in sandbox mode. You need to register all of your destination email addresses in the SES console for anything to work. Click on the
Email Addresses
link to list your verified addresses and add more. Also, you will need to set upAWS IAM
credentials to use with the gem. When you do this, make sure the user has the SES Full Access managed policy attached (on the IAM console). :server
setting - AWS operates in multiple regions but your SES account will be set up in one of them. To determine your region, go to the AWS console and click on SES. You will see your region in the URL - for me it isregion=us-west-2
. I recommend setting up an initializer as described in Dan Croak's excellent article. I did it just as Dan recommended, except that I set the delivery method to:amazon-ses
and added a server configuration line.- Configuration - Dan's article (mentioned above) explains how to set
delivery_method
in your environment configuration file. Again, I used:amazon-ses
. - Once you have AWS configured and your gem installed, you can test your setup in the rails console. Much easier to troubleshoot there than in your code base.
- Somewhat unrelated, but I used the
Dotenv
gem to manage my environment settings. In a nutshell, once you install the gem, you can stick all of your environment settings in~/.env
and have access to them inENV
throughout your code.
/config/initializers/amazon-ses.rb
/config/initializers/amazon-ses.rb
ActionMailer::Base.add_delivery_method :amazon_ses, AWS::SES::Base,
:access_key_id => ENV['AWS_SECRET_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
:server => 'email.us-west-2.amazonaws.com'
/config/environments/development.rb(节选):
/config/environments/development.rb (excerpts):
# Configure mailer for development test
config.action_mailer.raise_delivery_errors = true
# Configure mail using AWS SES
config.action_mailer.delivery_method = :amazon_ses
# Configure URL options
host = 'www.example.com'
config.action_mailer.default_url_options = { host: host }
当然,为了使这项工作在生产中,你需要进行这些修改 /config/environments/production.rb
。您还需要为您的生产服务器上使您的AWS秘密设置。如果您正在使用Heroku的:
Of course, to make this work in production, you'll need to make these changes to /config/environments/production.rb
. You'll also need to make your AWS secret settings on your production server. If you are using Heroku:
$ heroku config:add AWS_SECRET_KEY_ID=12345XYZ
$ heroku config:add AWS_SECRET_ACCESS_KEY=67890ABC
这篇关于AWS SES超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!