Home > computer > Configuring Rails To Use Gmail’s SMTP Server

Configuring Rails To Use Gmail’s SMTP Server

February 20th, 2007

OpenRain.com uses Google Apps For Your Domain, and all email flows throw Google’s servers. Unfortunately, Rails 1.2.2 can’t send via smtp.google.com out of the box. As originally pointed out by Anatol Pomozov there is a solution. Here’s the simple version tested with Rails 1.2.2.

  1. Save this code as lib/smtp_tls.rb within your rails app.
  2. Add this code to config/environment.rb.
  3. Use ActionMailer as normal.

Updated 2008.01.04: The original link was b0rken, so I pastied the code instead.

  • Share/Save/Bookmark

preston.lee computer

  1. February 21st, 2007 at 23:57 | #1

    Just a note: if you’re copying and pasting the code from this page, know that the single- and double-quotes are being pasted as non-parsable versions. You’ll need to re-type those quotes to avoid read errors.

  2. Al Brown
    February 23rd, 2007 at 01:19 | #2

    action_mailer_tls seems to work with the same config I used with Rails 1.1.6

  3. Paul
    May 5th, 2007 at 21:37 | #3

    The links to the code seem to be broken. Is the code available anywhere else?

    Thanks

  4. May 6th, 2007 at 11:02 | #4

    The links seem to be working fine this morning. Maybe he just had some downtime yesterday.

  5. August 15th, 2007 at 13:47 | #5

    The website was down for me too.
    I searched google for the link:
    http://blog.pomozov.info/posts/how-to-send-actionmailer-mails-to-gmailcom.html
    and was able to get the code via the google cache.

  6. August 31st, 2007 at 07:07 | #6
  7. SandyTheFire
    January 3rd, 2008 at 14:26 | #7

    Guyz, I am trying to send multiple mails so i have to authenticate multiple times which consumes a hell lotta time, can anyone suggest a way.

  8. January 4th, 2008 at 22:48 | #8

    @SandyTheFire

    I’m not sure how to best deal with that within Rails, but you could use your own SMTP server instead. If your sending a ton of emails you may need to do that anyway to avoid getting slapped by Google.

  9. January 4th, 2008 at 22:48 | #9
  10. February 19th, 2008 at 12:37 | #10

    Gmail will limit you to send 500 emails per day.
    You won’t be able to change the “from” parameter.

    Perfect for personal use.

  11. February 19th, 2008 at 12:41 | #11

    /Users/prat/lib/rubygems/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:266:in `load_missing_constant’: uninitialized constant ActionMailer (NameError)

    Got this Error when starting mongrel.

  12. March 28th, 2008 at 19:33 | #12

    gracias por tu instructivo, por el cual logre lo que necesitaba.

    saludos desde colombia

  13. liquidsun
    August 15th, 2008 at 18:05 | #13

    For the ‘load_missing_constant’ error, here is the fix…
    Put
    require ’smtp_tls’
    require ‘action_mailer’
    into environment.rb.

  14. November 8th, 2008 at 12:56 | #14

    Alright folks,
    great tutorial – it came in very handy today.

    I would just like to add, for anyone who cares, that the code you need to insert into environment.rb, needs to go AFTER everything else in the file. i.e. after the ‘end’ statement.

    anyway, thanks a lot for this, I really needed it.

    Cheers

  1. February 22nd, 2007 at 02:24 | #1
  2. June 22nd, 2007 at 08:04 | #2
  3. August 23rd, 2007 at 09:33 | #3
  4. October 29th, 2007 at 04:44 | #4
  5. January 5th, 2008 at 00:39 | #5
  6. March 27th, 2008 at 08:50 | #6
  7. May 30th, 2008 at 14:06 | #7
  8. November 28th, 2008 at 00:50 | #8