Using Amazon SES for email delivery in Rails 3

Recently, Amazon added a new product to their cloud services kitty called as Amazon SES(Amazon Simple Email Service). The service can be used for bulk and transactional emails by developers and businesses alike. So as you might have guessed by now, the service competes head on with Postmark, Sendgrid, socketlabs etc. The simple reason for scrapping the said services and going ahead with Amazon SES is the price, thats it !! Now, lets dive deep into how to get Amazon SES running with a simple web application(We will be using rails3 as an example client application in this writeup): Setting up Amazon SES for delivering emails 1. Apply for the activation of SES in your amazon AWS account. If you are an existing AWS user, you will already be getting Amazon marketing promos to activate SES. Or you can sign up for ses here. 2. By default Amazon SES will be activated in a sandbox mode. This means that all the email addresses that you will be sending mails to, will need to be verified otherwise the email wont be delivered. Also, with verified email addresses, you can send up to 200 messages per day, at a maximum rate of 1 message per second 3. To get your email addresses verified, download Amazon SES scripts 4. To run the SES verification script, Perl must be installed on your system with the dependent modules. 5. Run the following command: -k creds.txt -v Amazon will send an email at the specified address. Please click the link in that email and you are done with the verification process. You are now done with verifying this email address. Please note that creds.txt here contains the AWS credentials. A sample creds.txt file looks like: AWSAccessKeyId= your_access_key AWSSecretKey= your_secret_key 6. After testing your emails in the sandbox, you can click here to Request for Production Access to Simple Email Service. They say it may take up to 24 hours, but my access request was granted in about 30 minutes – now I can send to any address! This was all about setting up Amazon SES. Now lets move to integrating the setup with a Rails 3 application. Configuring a Rails 3 application to send mails through Amazon SES: There are already a number of open source gems/plugins available to configure action mailer to send email thro Amazon SES but we decided to go ahead with drewblas/aws-ses (the aws-ses gem) for a simple reason that it works painlessly. Now: 1. Add ses to the gem file
gem "aws-ses"
2. Extend ActionMailer in config/initializers/your_config_file.rb, where config_file.rb is the name of the file which contains initialization routines for ses gem:
ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base,
  :access_key_id     => ENV['AMAZON_ACCESS_KEY'],
  :secret_access_key => ENV['AMAZON_SECRET_KEY']
3. Configure action mailer to send thro ses. In config/environments/*.rb
config.action_mailer.delivery_method = :ses
Thats it !! You are now ready to send mails from rails app thro Amazon SES. Happy Mailing !!