How to use GMail’s SMTP Server with Rails
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 => "smtp.gmail.com", :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!
February 23, 2007 at 8:21 am
No problem :)
February 23, 2007 at 10:56 pm
Enjoy it ;)