Sending mail via GMail with Rails ActionMailer

By default, ActionMailer cannot send email through GMail as it does not support SSL (TLS) and GMail requires this.  After browsing the various solutions to this problem people have come up with, I settled on the use of the tlsmail gem as being the simplest and most elegant solution, as described here.

To implement this, simply

sudo gem install tlsmail

and in your environment.rb, configure ActionMailer as follows:

require 'tlsmail'
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.raise_delivery_errors = true

ActionMailer::Base.smtp_settings = {
  :domain          => "yourdomain.com",
  :address         => 'smtp.gmail.com',
  :port            => 587,
  :tls             => true,
  :authentication  => :login,
  :user_name       => 'your_gmail_username',
  :password        => 'your_gmail_password'
}

Of course your perform_deliveries and rails_delivery_errors settings will probably vary, being different in the different Rails development / production environments.

1 comment to Sending mail via GMail with Rails ActionMailer

You must be logged in to post a comment.