Douglas F Shearer

GMail SMTP with Ruby on Rails and ActionMailer


Trying to use GMail SMTP (or some other SMTP authenticated with TLS) with ActiveRecord to send email in Ruby on Rails? Up till now this involved requiring smtp_tls.rb in your environment.

Thankfully, Kyle Maxwell has come up with a neater solution.

Install

It’s a plugin, which you can get with this command in your Rails root…

./script/plugin install http://svn.kylemaxwell.com/rails_plugins/action_mailer_optional_tls/trunk/

Due to continued downtime of Kyle’s site please use the following URl:

./script/plugin install http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls

Setup

You can turn TLS authentication on and off as you need in your environment with a new key that is added to the smtp config, tls. To use with gmail, the following should be in your environment.rb...


ActionMailer::Base.smtp_settings = {
    :tls => true,
    :address => "smtp.gmail.com",
    :port => "587",
    :domain => "YOURDOMAIN",
    :authentication => :plain,
    :user_name => "GOOGLEUSERNAME",
    :password => "GOOGLEPASSWORD" 
  }

And that’s it. Enjoy.

Tags

, , , , .

Related Posts

January 20th 2008 11:40 | comments (12)
 

Comments


Gravatar

Hugo

January 29th 2008 20:52

Hi,
I couldnt access the plugin URL.
Can you send it to me?
Is it the same plugin as this:
http://www.stephe...

Tks

Gravatar

Douglas F Shearer

January 29th 2008 21:32

Looks like Kyle's site is down, I shall email you the plugin.

This plugin is a new one that does the same thing as the one you link to, but is almost 2 years newer and Rails 2.0 compatible.

Gravatar

jesse

January 31st 2008 21:24

Hey,
could you be so kind and mail it to me also?

Thanks in advance ;-)

Gravatar

Mike

February 2nd 2008 04:07

Any chance I could get in on that e-mail? I'd really appreciate it.

Gravatar

Douglas F Shearer

February 5th 2008 00:44

This plugin is now hosted on my SVN until Kyle's site reappears.

Thanks.

Gravatar

Alan

February 14th 2008 19:43

Thanks for this! Saved me a lot of time and effort.

Gravatar

Mark S

April 22nd 2008 02:23

Good lad, well done ;-)

Gravatar

Calvin C

May 5th 2008 02:53

Rocks.
Quick and easy plugin installation and implementation.
Thanks for hosting it.

Gravatar

Miguel C

May 13th 2008 17:38

Thanks.

It works when sending e-mails to gmail accounts.

But e-mails sent to hotmail accounts will not even reach the spam box.

Is it a wrong setting?
Is it that hotmail discards every mail send via gmail smtp relay?

If that is the case, this mailer setup cannot be used in production mode.

Gravatar

Carl

July 3rd 2008 20:27

I've been trying to get something like this working since I use Google Apps for about 5 hours and nothing quite worked until now. Thank you big time!

Gravatar

Burt

July 9th 2008 01:08

There is a change in ruby 1.8.7 that breaks this app.

The symptom is an error like "(wrong number of arguments (3 for 2))" when sending a mail via tls.

The quick fix until the authors make a permenant fix is to remove authtype from the call to check_auth_args on line 33 of action_mailer_optional_tls/lib/smtp_tls.rb

see: http://www.redmin...

Gravatar

Sean Ouimet

July 29th 2008 03:58

Thanks for this! Big help!

Add Your Comments


(Required)

Your email address to get your Gravatar. Address itself is not shown.

(Include the http://)

(Required)

 

You Are Here


Douglas F Shearer

This is the homepage of Douglas F Shearer, a software developer and mountainbike racer. Find out more at the About page.

Gallery Latest


Side on Chips on crown Front on chip2 chip1 img67

Stay Informed


What is RSS?

Top Tags