What is Amazon SES?
Amazon SES is an email platform that provides an easy, cost-effective way to send and receive email using your own email addresses and domains. Sending Email with Amazon SES using SMTP You can use Simple Mail Transfer Protocol(SMTP) to send emails by using Amazon SES. You need an Amazon SES SMTP username and password to access the Amazon SES SMTP interface. To create SMTP credentials: 1. Sign into the AWS Management Console and open the Amazon SES console at https://console.aws.amazon.com/ses. 2. In the navigation pane, click SMTP Settings. 3. In the content pane, click Create My SMTP Credentials. 4. In the Create User for SMTP dialog box, you will see that an SMTP username has been filled in for you. You can accept this suggested username or enter a different one. To proceed, click Create 5. Click on Show User SMTP Credentials. Your SMTP credentials will be displayed on the screen; copy them and store them in a safe place. You can also click Download Credentials to download a file that contains your credentials. After creating your SMTP credentials, open the Verified Senders/Email Addresses screen. Before you can send an email using Amazon SES, you have to own an address or addresses which are going to be used as senders across the SES SMTP mail servers. Configure mailer with SMTP with rails app: Add the following code in config/environments/*.rb| config.action_mailer.delivery_method = :smtp | |
| config.action_mailer.smtp_settings= { | |
| :address => ‘email-smtp.us-east-1.amazonaws.com‘, | |
| :authentication => :login, | |
| :user_name => ‘<previously configured smtp username>‘, | |
| :password => ‘<previously configured smtp password>‘, | |
| :enable_starttls_auto => true, | |
| :port => 465 | |
| } |
| Class SesMailer < ActionMailer::Base | |
| default from: ‘test@example.com‘ | |
| def welcome | |
| mail(to:‘somebody@email.com‘, subject: ‘I emailed from AmazonSES!‘) | |
| end | |
| end |
| Welcome email! |
| #call deliver from mailer action | |
| SesMailer.welcome.deliver |
Sending emails using aws-ses gem:
1. Add aws-ses to the gem file – https://github.com/drewblas/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‘] |
| Config.action_mailer.delivery_method = :ses |