Sending email in Rails via GMail & using HAML with Action Mailer
Sending Email via Gmail
I was following the Action Mailer Rails Guide to set up outbound email from my app and I came across a problem when trying to use GMail. Many blog posts and the Rails guide point to plugins which enable TLS. I kept running into a wall and getting this error:
wrong number of arguments (3 for 2)
Luckily I finally found there is a very simple solution which is defined in the Rails API in ActionMailer::Base. This essentially says that Section 5.2 of the Rails Guide can be simplified by adding an additional parameter to the smtp_settings:
1 2 3 4 5 6 7 8 9 | ActionMailer::Base.smtp_settings = { :enable_starttls_auto => true, :address => "smtp.gmail.com", :port => 587, :domain => "domain.com", :user_name => "user@domain.com", :password => "password", :authentication => :plain } |
There is no plugin / gem needed, but you must be on Ruby 1.8.7
From the Rails API:
:enable_starttls_auto - When set to true, detects if STARTTLS is enabled in your SMTP server and starts to use it. It works only on Ruby >= 1.8.7 and Ruby >= 1.9. Default is true.
Using HAML with ActionMailer
Section 5.3 of the Rails Guide also mentions a configuration setting to get Action Mailer to recognize HAML templates. This configuration is not needed. As I found here.
I added comments to the Rails Guide Lighthouse ticket, so hopefully the guide will be updated.
Related posts:
- Reversing Your Email Composition [Idea] « On Organization If you have ever sent an email without including an...
- Book Review: Rails Freelancing Handbook As part of helping out on a RailsBridge project, I...
Related posts brought to you by Yet Another Related Posts Plugin.
Comments
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!










