ActionMailler and Gmail (no plugins)

Last week I run into some problems while configuring the ActionMailler with Gmail. I have already some applications in production using this method. However this one, using ruby 1.8.7 and rails 2.3.3 gave me extra trouble.

Gmail requires TLS, older versions of ruby and rails do not support that, the work around was a pluging to enhance it (ActionMailerTLS). But if you are using Ruby 1.8.7 with Rails 2.2.1, or later versions, you don’t need plugins anymore, you only need to follow this simple instructions.

Add the following lines in your config/enviroments/production.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = YAML.load"#{RAILS_ROOT}/config/mailer.yml")

And then create the yaml file config/mailer.yml :

:enable_starttls_auto: true # This is how you tell ActionMailler to use tls
:port: 587
:user_name: my_username #You should type your username, you should not include the "".
:password: my_password #You should type your password
:authentication: :plain

That’s it!

Now take a look in this notifier class example:

class Notifier < ActionMailer::Base
def activation_instructions(user)
@recipients = "#{}"
#@from = "Miguel <>" # Doesn't work anymore
@from = ""
@subject = "[Card-Sorting] "
@sent_on =
@subject += "Important"
@body[:user] = user

There is a lack of backward compatible. Due to some changes in the latest versions you cannot use that syntax anymore, if you are upgrading from old versions be careful, you should only simply specify your email to get it correctly parsed.


comments powered by Disqus