small medium large xlarge

13 Jun 2008, 17:12
Larry Cummings (1 post)

I’ve been having quite the time getting this recipe to do anything. A little “here’s a good way to debug this” help would have helped this section.

Couple things that worked for me.:

1) the svn repository provided does not respond at all. A comment in Daniel Fischer’s original post about this provides a working repository here: (and incidentally nanorails will work with script/plugin install).

2) once installed, I can’t get it to work on the live server. Mysteriously it connects like a champ when I run it locally (it makes no difference if I run it in Production or Development mode, btw).

Here’s the output I get when I run it from the console on the live server:

>> user.send_password_reset
-> "220 ESMTP c29sm5627467anc.38\r\n"
<- "EHLO \r\n"
-> " at your service, []\r\n"
-> "250-SIZE 28311552\r\n"
-> "250-8BITMIME\r\n"
-> "250-STARTTLS\r\n"
<- "STARTTLS\r\n"
-> "220 2.0.0 Ready to start TLS\r\n"
<- "EHLO \r\n"
-> " at your service, []\r\n"
-> "250-SIZE 28311552\r\n"
-> "250-8BITMIME\r\n"
-> "250-AUTH LOGIN PLAIN\r\n"
<- "AUTH PLAIN AGxhcnJ5QHNoYWRvd2JveC5jb20Ac2MwMFRlcnMh\r\n"
-> "535-5.7.1 Username and Password not accepted. Learn more at         \r\n"
-> "535 5.7.1 c29sm5627467anc.38\r\n"
=> #<TMail::Mail port=#<TMail::StringPort:id=0x..fb7da2a0> bodyport=#<TMail::StringPort:id=0x..fb7d9224>>

Any ideas?

07 Jul 2008, 21:14
Jason Schmidt (4 posts)

Here is the code I have used, and works in both dev and production…

  • config/initializers/smtp_gmail.rb

require “smtp_tls”

ActionMailer::Base.smtp_settings = { :address => “”, :port => 587, :domain => “”, :authentication => :plain, :user_name => “”, :password => “PASSWORD” }

  • vendor/plugins/action_mailer_tls/init.rb

require_dependency ‘smtp_tls’

  • vendor/plugins/action_mailer_tls/lib/smtp_tls.rb

require “openssl” require “net/smtp”

Net::SMTP.class_eval do private def do_start(helodomain, user, secret, authtype) raise IOError, ‘SMTP session already started’ if @started check_auth_args user, secret, authtype if user or secret

sock = timeout(@open_timeout) {, @port) }
@socket =
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output

check_response(critical { recv_response() })

raise 'openssl library not installed' unless defined?(OpenSSL)
ssl =
ssl.sync_close = true
@socket =
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output

authenticate user, secret, authtype if user
@started = true   ensure
unless @started
  # authentication failed, cancel connection.
    @socket.close if not @started and @socket and not @socket.closed?
  @socket = nil
end   end

def do_helo(helodomain) begin if @esmtp ehlo helodomain else helo helodomain end rescue Net::ProtocolError if @esmtp @esmtp = false @error_occured = false retry end raise end end

def starttls getok(‘STARTTLS’) end

def quit begin getok(‘QUIT’) rescue EOFError end end end

07 Jul 2008, 21:14
Jason Schmidt (4 posts)

Uck. Code formatting got all wacky

09 Jul 2008, 22:29
Daniel Fischer (1 post)

If it works locally, nothing should be preventing it from working on your server besides server related misconfiguration.

Double check your iptables.

One other thing I’d double check, and this is from experience, make sure your e-mail account on google wasn’t flagged for spam. That happened on production for me because I was testing it by sending mail to and because I was going through gmail for that, they labeled that account as “spam”. So, try create a new account and use those settings. It should work.

22 Jul 2008, 17:44
Jay (3 posts)

Your issue may be related to ruby versions. A 1.8.7-compatible version of this plugin has not been released yet (check date of this post). If you want to use ruby 1.8.7 right now, you can hack the plugin yourself: the smtp_tls.rb file needs to be changed on line 8. 8 #change below for 1.8.7 9 #check_auth_args user, secret, authtype if user or secret 10 check_auth_args user, secret if user or secret

Alternatively, you can use ruby 1.8.6 versions until a compatible plugin comes out for 1.8.7.

08 Feb 2009, 22:14
Saul Mora (1 post)

In case anyone needs it, OpenRain has been migrating their library of opensource code to github lately. The action_mailer_tls code is now here:

11 Feb 2009, 17:54
Marc Chung (3 posts)

Hi everyone,

I’m the original author of this plugin.

I apologize for the SVN issue. I was only recently made aware that the URL for the repository was directly referenced in Advanced Rails Recipes.

Like Saul mentioned, we’ve moved a lot of our code over to GitHub. The code’s new home is now referenced here:


Some additional notes:

  • The plugin is now a gem, which means that it’s easier to install and to add to vendor/gems via config.gem.
  • The gem does not work on Ruby 1.8.7 since this version changes method signatures.
  • However, if you’re running Ruby 1.8.7 with Rails 2.2.1, then this gem is no longer necessary.
  • Ruby 1.8.7 ships with TLS support which is supported by Rails 2.2.1 out of the box

To enable support for TLS with Rails 2.2.1, you need an initializer (for example, config/initializers/smtp_gmail.rb) with the following settings:

ActionMailer::Base.smtp_settings = {
  :address => "",
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
  :password: h@ckme

Currently the gem does not have support for Ruby 1.8.7.

11 Feb 2009, 17:57
Marc Chung (3 posts)

Obviously, the “:user_name” field in the snippet of YAML doesn’t need to have the anchor mailto link. It was added by the forum

11 Feb 2009, 19:23
Marc Chung (3 posts)


I’m sure you’ve already figured this out by now.. but for everyone else:

The problem you’re specifically seeing is caused by an incorrect username and password combination. Make sure it’s the full email address (“” or “”). Also, the YAML file requires no quotes. See my previous YAML example.

(Assuming that is run by Google Apps)

30 Aug 2009, 18:21
Mike Diamond (1 post)

Answered my question, thanks.

25 Nov 2009, 12:25
Steven Noble (21 posts)

So if it’s now a gem not a plugin, we don’t need ‘require “smtp_tls”’ at the head of config/initializers/smtp_gmail.rb?

You must be logged in to comment