Simplify Rails configuration for sending email

written by seb on February 11th, 2007 @ 02:09 PM


We got great thing for configuration of the database but as I know it’s harder to do the same for sending email.

Here is a simple library, load_email_configuration.rb that may help to keep the basic settings out of the rest of the code, as database.yml do.

Once you put this library in the right place, lib/ you’ll need to include it in your config/environment.rb file

# Load email configuration
require 'load_email_configuration'

If you checked the library source (if you didn’t, you should ;-)) you see that it’s gonna load the file config/email.yml and will load different settings depending on the environment.

There is an example of email.yml file : email.example.yml

Once you get the library included and your config/email.yml file properly modified you got to be sure that ActionMailer is well set.

In my case I use such configuration for development (so in config/environments/development.rb:

# Care if the mailer can't send
config.action_mailer.raise_delivery_errors = true

# Use SMTP protocol to deliver emails
config.action_mailer.delivery_method = :smtp

# Don't send emails
config.action_mailer.perform_deliveries = false

and this one for production (so in config/environments/production.rb:

# Disable delivery errors if you bad email addresses should just be ignored
config.action_mailer.raise_delivery_errors = false

# Use SMTP protocol to deliver emails
config.action_mailer.delivery_method = :smtp

For more about ActionMailer configuration please read the api documentation

Now you did all this things, don’t forget to restart your server ;-)

UPDATE : On shared host using FCGI you should just wait few minutes for the changes to take effects, if that still not working try killall -usr1 dispatch.fcgi

Have fun, and do NOT spam ;-)

Comments are closed