Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

How to use GMail’s SMTP Server with Rails

By Peter Cooper / February 22, 2007

Rails' ActionMailer library can send e-mail for you, and while it can be set up to use almost any SMTP server, special requirements by Google's GMail SMTP server have presented Rails users from taking advantage of it. Ages ago I mentioned a solution to the problem, but it involved downloading a separate application called 'msmtp' and performing an ugly system call from your application.

There's a far cleaner solution, and it's escaped my attention for almost five months now. Anatol Pomozov has written a small library using net/smtp and OpenSSL that changes some of net/smtp's methods to allow it to directly talk to secure SMTP servers such as GMail's. He also presents an example of what to do in your Rails application that looks like this:

require 'smtp_tls'

ActionMailer::Base.server_settings = {
  :address => "",
  :port => "587",
  :domain => "localhost.localdomain",
  :authentication => :plain,
  :user_name => "someusername",
  :password => "somepassword"

Enjoy! Thanks to Preston Lee for pointing this out. And, of course, Anatol's smtp_tls library can also be used directly from any other Ruby application if you like!


  1. Preston Lee says:

    No problem :)

  2. Anatol Pomozov says:

    Enjoy it ;)

Other Posts to Enjoy

Twitter Mentions