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
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.
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.
As I mentioned in my question, the
MailForm
andAWS-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.Some keys to setting up
AWS-SES
(code included below for reference):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.delivery_method
in your environment configuration file. Again, I used:amazon-ses
.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/environments/development.rb (excerpts):
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: