Updating Gmail SSL SMTP Support for Ruby 1.8.7
January 13th, 2009
In Adding Gmail SSL SMTP Support to Rails I described the use of a simple Rails plugin to provide SSL SMTP support. Today I upgraded to a new version of Mephisto and while testing it in production I discovered that I couldn't send emails. It turns out that it had nothing to do with the Mephisto upgrade; my DreamHost server had been updated to Ruby 1.8.7 and the action_mailer_tls plugin I was using wasn't compatible. Oh well, I guess I deserved that surprise for using shared hosting and adding a monkey patch plugin. This post describes a simple fix.
The problem occurred because the 1.8.7 version of Net::SMTP changed its private check_auth_args method. Fortunately, I had just removed the action_mailer_tls plugin from Cached Externals so I was able to do a quick code fix in the plugins directory. Here's the change I made to vendor/plugins/action_mailer_tls/lib/smtp_tls.rb.
In Net::SMTP.class_eval#do_start replace:
8 |
check_auth_args user, secret, authtype if user or secret |
with:
8 9 10 11 12 13 14 |
RUBY_VERSION.match(/(\d+)\.(\d+)\.(\d+)/) if ($1.to_i <= 1 && $2.to_i <= 8 && $3.to_i <= 6) check_auth_args user, secret, authtype if user or secret elsif user or secret check_auth_method(authtype || DEFAULT_AUTH_TYPE) check_auth_args user, secret end |
Check it in:
[mac]$ git add vendor/plugins/action_mailer_tls/lib/smtp_tls.rb [mac]$ git commit -a -m "Fixed auth check method for 1.8.7 compatibility."
And deploy it:
[mac]$ cap deploy
If you're starting from scratch and want something that already works I did notice there are other similar solutions with 1.8.7 support available on the Internet. Simplificator's tls-support gem on github is one example.
Sorry, comments are closed for this article.