Using Gmail to send email from your rails app

We wanted to send via gmail for testing reasons. We develop locally, but we want to see how our emails would be formatted in a standard mail client. Which means we need a valid email to send from. The main problem we’re trying to avoid is our test emails getting canned as spam, which is more likely to happen if we’re just sending direct from a local machine.

If you’re using rails 1.8.6 or lower, you will need to use the action_mailer_optional_tls plugin or the actionmailer_tls plugin to achieve this result. We run all our apps on 1.8.7 for the time being, so happily we can use this simpler method.

Firstly, setup a test email account on gmail. This works fine for normal or apps gmail accounts. Then you need to add these lines to wherever you do your basic actionmailer config. In our case, we added this to our development.rb as we’re just using this to test email output for the time being.

config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "",
:port => "587",
:domain => "", 
:authentication => :plain,
:user_name => "",
:password => "your_password_here"

Voila, our emails are sent fine, which makes testing the output a great deal easier, especially if you have to produce html emails.

What we’re doing here is bascially just using standard gmail setup for configuing a mail client. Obviously you could just replace these options for another smtp server if you’d like.


There are no comments yet...Kick things off by filling out the form below.

Leave a Comment