The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Sending Mail Through Gmail with Ruby's Net::SMTP

1 reply on 1 page. Most recent reply: Jul 24, 2010 10:04 AM by John Stasko

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
James Britt

Posts: 1319
Nickname: jamesbritt
Registered: Apr, 2003

James Britt is a principal in 30 Second Rule, and runs ruby-doc.org and rubyxml.com
Sending Mail Through Gmail with Ruby's Net::SMTP Posted: Dec 18, 2007 3:30 PM
Reply to this message Reply

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
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by James Britt
Latest Posts From James Britt: Ruby Development

Advertisement

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

    require 'net/smtp'
    require 'smtp_tls'

     username = 'joeblow'
     password = 'topsekrit'
     msg = some_code_that_builds_my_message
     Net::SMTP.start(   'smtp.gmail.com' , 
                                  597, 
                                  'localhost.localdomain', 
                                  username, 
                                  password, 
                                  'plain' ){ |smtp|
        smtp.send_message(  msg, 
                              "joe.blow999@gmail.com", 
                                bono@number2yeahyeahyeah.org" )
    }

More or less.

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.

Read: Sending Mail Through Gmail with Ruby's Net::SMTP


John Stasko

Posts: 1
Nickname: industrial
Registered: Jul, 2010

Re: Sending Mail Through Gmail with Ruby's Net::SMTP Posted: Jul 24, 2010 10:04 AM
Reply to this message Reply
ArgumentError: wrong number of arguments (3 for 2)
from (irb):42:in 'check_auth_args'

So I pasted that file for the tsl mixin into IRB to check this out and I got this error.

However, this would be powerful if it worked. Thank you for the help.

Flat View: This topic has 1 reply on 1 page
Topic: Popular Posts on Clojure from RubyLearning Previous Topic   Next Topic Topic: Debugging Multiple SWFs

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use