Rolling Windows and Sticky Bytes

<tagline type="clever"/>

Ruby on Rails SMTP Foibles

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 => "mail.example.com",
 :domain => "example.com",
 :port => 25,
 :user_name => "account@example.com",
 :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
1 Comment »

Ruby on Rails Asset Pre-compliation for Heroku

A couple of weeks ago while I was working on a Ruby on Rails application, I ran into an issue with assets failing to pre-compile. Rake threw the following message:

rake aborted!
 application.scss isn't precompiled

After spending a day trying to figure out what was wrong with my code, I discovered it’s a bug in the version of Rails I was using. Upgrading to Rails 3.2.0 did the trick.

Just as a quick reminder to myself, the following command will clean (delete!) the pre-compiled assets:

RAILS_ENV=production bundle exec rake assets:clean

The following command will run the pre-compile:

RAILS_ENV=production bundle exec rake assets:precompile

Once the assets are compiled, add them to your git repository and run:

git push heroku
No Comments »