Paul Kincaid-Smith

Director of Ecosystem Development at SendGrid



Email for your App

Does your app need to send email? Most do, and I'll show you how. This project will demo how to send mail reliably from the cloud.  

SendGrid is a developer-friendly email delivery service that does waaay more than just deliver your email. Since virtually every mature web application sends email (e.g. account signup confirmations, password reset messages, purchase notifications, etc.) I will extend Mattan's One Month Rails project to include email notifications which will be delivered for free via SendGrid.

Take my OMR app for a spin on Heroku: It looks familiar, right? Just like yours did. No magic here... but see below for something special.

Look at the source code on Github:

What really counts is my gift to you: a separate code repository for an email prototype Rails app. See below:

Project status:

7 April '13:  I built a separate Rails project to demonstrate the sending of email. The simple prototype works! I published this simple email prototype to Github (to help you). TBD: Next, I will add the email functionality to my own evolving OMR project. This will involve tinkering with "devise", the gem for creating users. Devise is cool, but somewhat complicated.

9 April '13: Tinkering with the devise gem to modify the user signup process is a bit complicated. Grrrr.

My gift to you: A simple prototype that demystifies how to send email from a Rails app. See fully-functional code here:

OK, now it's your turn. Time to learn how to add email notifications to your Rails app! Here are some tips for which will spare you hours of troubleshooting:

1. Check out this helpful RailsCast on ActionMailer, but the mail gem has been updated since the RailsCast was recorded, so make the following changes:

  • In your Gemfile, add gem "mail", not the obsolete gem "mail", "2.1.3"
  • In setup_mail.rb, put double quotes around the port number, like this :port => "587",

2. While you're working on prototyping the simple mailit rails app in the RailsCast above, sign up for a free SendGrid account (your request will be reviewed, and this may take a few hours to a day, so fill out the application form soon).

3. Reconfigure your simple standalone application to use SendGrid. Adapt the example here:

4. Never put your SendGrid login credentials in a file which will be uploaded to a publicly-visible location (like Github) -- you don't want someone else to take control of your account or use it to send spam. Instead, you could use environment variables to "feed" the SendGrid username and password to your application. See an example here.

Take a look at this sample code, which shows you how to set up a simple email prototype:, and pay particular attention to the setup_mail.rb file, where I explain how to pass in your email server credentials securely. (That's the secret sauce!)


Please sign in or sign up to comment.