Silence is Foo Mental notes on Ruby, Git, Rails and whatever geeky thing

7Feb/11Off

Configuring Rails’ ActionMailer to work with sendmail in Linux

For some reason I wanted to use sendmail as delivery method in a Rails 3 project I'm working on, the configuration was easy, you can check it out in the official ActionMailer Basics Guide, but I'll show you here the most important line:

Put it in your config/application.rb to use sendmail globally or in any of your environment files, like config/environments/development.rb:

config.action_mailer.delivery_method = :sendmail

Everything worked just fine in my Mac OS X Snow Leopard, but it didn't in a Debian Lenny box with Exim4, and as far as I remember it never worked before in any of the linux boxes I used, but it never was a big deal because in most of the cases I use SMTP in production, but not this time, so here is what I did.

The default configuration for sendmail is:

config.action_mailer.sendmail_settings = {
   :location => '/usr/sbin/sendmail',
   :arguments => '-i -t'
}

This is set in the Rails' 3 ActionMailer's delivery_methods.rb file in the line 36, but the same applies for all the previous versions, at least since v0.9.1.

I didn't know what -i and -t were useful for, but that was easy to fix:

man sendmail

-t    When Exim is receiving a locally-generated, non-SMTP message on its standard input, the -t option causes
the recipients of the message to be obtained from the To:, Cc:, and Bcc: header lines in the message
instead of from the command arguments. The addresses are extracted before any rewriting takes place and the
Bcc: header line, if present, is then removed.

-i    This option, which has the same effect as -oi, specifies that a dot on a line by itself should not termi-
nate an incoming, non-SMTP message.

It sounded to me like the -t option might have something to do with the error, so I got rid of it and IT WORKED!, why?, don't ask me, it just worked, so here is my final configuration lines:

config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {:arguments => '-i'}

And as a bonus, if you're using the god gem to monitor your processes and you're having problems to send mail notifications with sendmail, you should know that it might be the same issue, click here to see the contacts/email.rb file, and you'll find that sendmail default arguments includes the -t option.

And that was it! See you!

Filed under: rails 2 Comments
3Sep/10Off

Accessing different versions of the Rails Guides

In case you're looking for older versions of the Rails Guides I just created a site with the v2.3.5 ones, besides, if you want to download the guides for the v3.0.0, you will be able to do so as well.

http://railsguides.heroku.com

You can download the source code of the site (Sinatra app) from Github:

http://github.com/rafmagana/rails_guides

Filed under: rails Leave a comment