Rolling Windows and Sticky Bytes

<tagline type="clever"/>

Ruby on Rails SMTP Foibles

on 2012-06-28

I recently ran into some minor difficulties while trying to get ActionMailer functioning on my Ruby on Rails site and it took me a couple of hours of head-on-desk time to straighten it out. Here are some caveats!

  1. You should use config/initializers/mail.rb for mail configuration information, not the regular environment definition files in config/environments/*.rb files. Separation of concerns and all that. This isn’t a strict rule but it made sense to me. Edit: As I discovered later, this advice is horribly wrong unless you are very sure you want the same mail setup in all of your environments (i.e. development, test and production). Since I don’t want my development or test environments sending out bogus notification e-mails, I have since broken the mail configuration back out into the config/environments/*.rb files.
  2. SSL / TLS defaults to true for mail connections in ActionMailer, at least in the version I am using. Since the mail server I’m using doesn’t have a proper certificate and the mail I’m transferring isn’t sensitive in any way, I turned off TLS by setting :enable_starttls_auto => false in my ActionMailer configuration.
  3. This one is an RTFM question but the difference between “plain” and “login” is that “plain” sends the username and password in plain text, where “login” uses base-64 encoding. Note that neither one is secure but my mail server expects base-64 encoded credentials so I set :authentication => :login for ActionMailer in my configuration.

Here’s an anonymized version of my config/initializers/mail.rb snippet from my config/environments/production.rb file for reference:

ActionMailer::Base.smtp_settings = {
 :address => "",
 :domain => "",
 :port => 25,
 :user_name => "",
 :password => 'Changeme02',
 :authentication => :login,
 # Disable TLS since we don't have a cert for this hostname
 :enable_starttls_auto => false
ActionMailer::Base.delivery_method = :smtp

One Response to “Ruby on Rails SMTP Foibles”

  1. Matt says:

    Love the visibility of lessons learned through strike through. Excellent thoughts my friend! Keep them coming.


Leave a Reply

Your email address will not be published. Required fields are marked *