This post originated from an RSS feed registered with Ruby Buzz
by James Britt.
Original Post: Sending Mail Through Gmail with Ruby's Net::SMTP
Feed Title: James Britt: Ruby Development
Feed URL: http://feeds.feedburner.com/JamesBritt-Home
Feed Description: James Britt: Playing with better toys
Setting up and maintaining a mail server can get annoying, so I’ve become a fan of using having my Ruby apps sending mail via Gmail.
For various reasons I hadn’t needed this for a while (sometimes I luck out and the deployment server has its own mailer server, maintained by Someone Other Than Me), but yesterday I wanted to have an application mail me when there is a problem, and I installed the Gmailer gem.
It didn’t work. It appeared to work, raising no errors or otherwise complaining, but mail never arrived anywhere.
A little debugging showed that the lib is using HTTP to talk to Gmail, and it seemed as if Google had changed the page routine.
If you’ve never tried this before, you may wonder why not just use the Net::SMTP library? The reason is that Google wants to talk using TLS, which Net:SMTP, out of the box, does not do.
However, after some prolonged Googling, I found a post on Nuclear Rooster that lead to a a post on Hatena::Diary with a very nice SMTP TLS mix-in.
I grabbed the code for smtp_tls.rb, pasted it into a local file, and was then able to send mail through the standard Ruby SMTP lib via smtp.gmail.com
Anyways, it makes it a snap to send through Gmail. Note that that Gmailer code offers more than just mail sending if you need assorted other Gmail goodness. But if you just want to get a message out, this works great.