Home Contact Sitemap

Preston Lee

Founder, CEO, OpenRain.com

About

During the day I run OpenRain in Phoenix: a Ruby on Rails development shop. During the night... well... I still have to run OpenRain, but when I find time to breath, I exhale here. If you'd like to get in touch professionally, don't hesitate to contact me via the OpenRain website.

Peace,

Preston

Configuring Rails To Use Gmail’s SMTP Server

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

. 20 Feb 07 | Computer


Reader's Comments

  1. Chris |

    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. Łukasz Schabowski // Weblog » Blog Archive » Rails & Gmail SMTP Server |

    [...] PrestonLee.com » Configuring Rails To Use Gmail’s SMTP Server [...]

  3. Al Brown |

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

  4. Paul |

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

    Thanks

  5. preston.lee |

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

  6. การตั้งค่าให้ Rails ใช้งาน Gmail SMTP Server « Kiterminal’s Blog |

    [...] ที่มา: PrestonLee.com   [...]

  7. Joe |

    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.

  8. How to use GMail’s SMTP Server with Rails « Bhushangahire’s Weblog |

    [...] Enjoy! Thanks to Preston Lee for pointing this out. And, of course, Anatol’s smtp_tls library can also be used directly from any other Ruby application if you like! [...]

  9. Jean-Michel Garnier |

    I have copied-pasted the code from google cache to http://21croissants.blogspot.com/2007/08/configuring-rails-to-use-gmails-smtp.html

  10. wwwaku » RailsでGmailã‚’SMTPサーバーとして使う方法 |

    [...] http://www.prestonlee.com/archives/63 http://21croissants.blogspot.com/2007/08/configuring-rails-to-use-gmails-smtp.html [...]

  11. SandyTheFire |

    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.

  12. preston.lee |

    @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.

  13. Marc Chung |

    It’s also available from our SVN repo

    https://openrain.com/opensource/public/rails/plugins/action_mailer_tls/

    -M

  14. PrestonLee.com » Blog Archive » Rails 2.0: Gmail SMTP With ActionMailer |

    [...] Note: I previously wrote about how to do this for Rails 1.2.x here. [...]

  15. Philippe Rathe |

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

    Perfect for personal use.

  16. Philippe Rathe |

    /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.

  17. Suave’s Blog » » send Email via Gmail of Google Apps in your Rails project |

    [...] 不过后来在一篇 Blog 的评论中看到说 Gmail 限制一天只能发 500 封邮件,Google 了一下貌似确有此事,还没有亲自证实。 [...]

  18. william |

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

    saludos desde colombia

  19. Scott Motte » Blog Archive » Email validation/activation with rails |

    [...] five [...]

  20. liquidsun |

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



Leave a Reply