Sorry this page looks weird. It was automatically migrated from my old blog, which had a different layout and different CSS.

SMTP over SSL with Fastmail

Anyone using Fastmail’s SMTP service to send email must upgrade their connection to use SSL before the end of June (this Saturday). In case there’s someone who has left it even later than I have, here’s how to change your Rails app’s configuration to use SSL.

It boils down to telling your Net::SMTP connection to enable TLS:

smtp = Net::SMTP.new(address, port)
smtp.enable_tls

SSL was introduced to the Mail gem in v2.4.0, which is used by ActionMailer 3.2.0 and up. Previous versions of ActionMailer need monkey-patching to crowbar in SSL support.

Rails 3.2 and up

In config/initializers/email.rb (or wherever you configure your SMTP):

ActionMailer::Base.smtp_settings = {
  address:              'mail.messagingengine.com',
  port:                 465,
  domain:               'yourdomain.com',
  user_name:            'your_username',
  password:             'xxxxxxx',
  authentication:       :plain,
  enable_starttls_auto: false,
  ssl:                  true
}

Rails 3.0 - 3.1

Use the configuration above for Rails 3.2, preceded with a monkey-patch for Mail. See this gist.

Rails 2.3

ActionMailer 2.3 uses TMail rather than Mail, but that’s ok. Use the configuration above for Rails 3.2, preceded with a monkey-patch for TMail. See this gist.

SSL vs TLS vs STARTTLS

Fastmail has an excellent explanation of SSL vs TLS vs STARTTLS.

Bonus: monit

If you use monit and monit alerts you via email, your configuration should look like:

set mailserver mail.messagingengine.com
               port 465
               username "your_username" password "xxxxxxx"
               using SSLV3
               with timeout 15 seconds

Andrew Stewart • 25 June 2012 • Email
You can reach me by email or on Twitter.