Setting up Rails to Send Emails with Amazon SES

The Amazon Simple Email Service is a cloud service inside AWS (Amazon Web Services) to send and receive email. I have used it to send emails, and it worked flawlessly. It has a reasonable maximum sending quota, and it’s pretty fast for a modest web app…


This content originally appeared on DEV Community and was authored by David Morales

The Amazon Simple Email Service is a cloud service inside AWS (Amazon Web Services) to send and receive email. I have used it to send emails, and it worked flawlessly. It has a reasonable maximum sending quota, and it’s pretty fast for a modest web application.

It has serious competitors, especially the service from MailChimp: Mandrill. But since they switched it to an add-on for MailChimp premium users, Amazon SES is, in my opinion, the first choice for small and medium web applications.

Initially, all users are placed in the Amazon SES sandbox (a test environment) to ensure the quality of service and avoid fraud. This has real limiting quotas for big applications, so a request must be filled to Amazon support to move out of the sandbox and get higher limits.

Before going on, you will need to sign up for an Amazon Web Services account. If you haven’t have one, go create one for yourself.

Verifying your domain

The first step is verifying the domain the emails will be sent from to prove the ownership. Don’t forget to generate DKIM settings, it is recommended to increase your domain trust.

This step will require to add some DNS records, so you will need access to your DNS panel.

Once all records are added, you will have to wait for them to propagate to the other internet DNS servers. This can take up to 24 hours to complete. For now you will see your domain listed in Amazon SES console as “pending verification”. Don’t worry, Amazon will check it automatically later on and verify your domain.

Creating the SMTP credentials

In order to use Amazon SES to send your emails you will need to authenticate using an SMTP endpoint.

Please go to your “SMTP Settings” page in your SES console. Here you can see your server name, note it down somewhere.

Click the “Create My SMTP Credentials” button. Amazon will ask you for a new IAS user name (IAS stands for Identity and Access Management), but they will provide you with a default one that you can safely accept. Click the “Create” button at the very bottom of the page.

Your credentials are now created! You can see them by unhiding them clicking the corresponding link.

Screen Shot 2021-03-10 at 16.44.39

There you will see your SMTP username and password. If you need to save a copy, click the “Download Credentials” button at the very bottom of this page, because you will not have access to these settings once this page is closed.

Configuring your Rails application

Open your config/environments/production.rb file and add this code inside the configure block:

config.x.mail_from = %(Your site name <no-reply@yoursite-domain.com>)
config.action_mailer.default_url_options = { host: 'yoursite-domain.com' }
config.action_mailer.smtp_settings = { address: 'email-smtp.eu-west-1.amazonaws.com', user_name: 'your_smtp_username', password: 'your_smtp_password' }
config.action_mailer.raise_delivery_errors = true

Sending your emails

Your new account is still in the Amazon SES sandbox. That means that you can only send email to addresses using your verified domain. This is intended to test the service and your application.

If you want to test the service sending an email to an email address of yours, you will have to add and verify it in the “Email Addresses” in the “Identity Management” section of your SES console.

So click the “Verify a New Email Address” button. Enter an email of yours and you will receive a verification email. Click on the link you will find inside that email that you have received. That’s it! You now have a verified email recipient to test the service with. Bear in mind that you should send the test email from this address too.

When you are happy with it, go to “Sending Statistics” in the “Email Sending” section in your SES console. You will find a button to open a request to move out of the sandbox. When it’s accepted, your application will be able to send emails to any email address in the Internet.

Conclusion

Alright! We have set up our Amazon SES service and our Rails application to work together. Really. You don’t have to make any other modification, just use Rails email sending methods as usual and it will work.

With this article I wanted to show how easy is to configure and use a service like this. If you ever want to switch to another service, I’m sure the process will be similar. At least from Rails’ side you’ll only need to adapt your SMTP settings.

Happy email sending!


This content originally appeared on DEV Community and was authored by David Morales


Print Share Comment Cite Upload Translate Updates
APA

David Morales | Sciencx (2021-03-10T16:05:56+00:00) Setting up Rails to Send Emails with Amazon SES. Retrieved from https://www.scien.cx/2021/03/10/setting-up-rails-to-send-emails-with-amazon-ses/

MLA
" » Setting up Rails to Send Emails with Amazon SES." David Morales | Sciencx - Wednesday March 10, 2021, https://www.scien.cx/2021/03/10/setting-up-rails-to-send-emails-with-amazon-ses/
HARVARD
David Morales | Sciencx Wednesday March 10, 2021 » Setting up Rails to Send Emails with Amazon SES., viewed ,<https://www.scien.cx/2021/03/10/setting-up-rails-to-send-emails-with-amazon-ses/>
VANCOUVER
David Morales | Sciencx - » Setting up Rails to Send Emails with Amazon SES. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/10/setting-up-rails-to-send-emails-with-amazon-ses/
CHICAGO
" » Setting up Rails to Send Emails with Amazon SES." David Morales | Sciencx - Accessed . https://www.scien.cx/2021/03/10/setting-up-rails-to-send-emails-with-amazon-ses/
IEEE
" » Setting up Rails to Send Emails with Amazon SES." David Morales | Sciencx [Online]. Available: https://www.scien.cx/2021/03/10/setting-up-rails-to-send-emails-with-amazon-ses/. [Accessed: ]
rf:citation
» Setting up Rails to Send Emails with Amazon SES | David Morales | Sciencx | https://www.scien.cx/2021/03/10/setting-up-rails-to-send-emails-with-amazon-ses/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.