Global Email Settings in Rails

I was running the functional test and didn’t realize it was sending actual emails from my data fixtures. However, I did learn how to globally set the email settings so not to send the emails out during tests.

If you want to use this, create a file called global_email_settings.rb (or whatever you want to name it) and put it in your your config/initializers/ folder. Restart your server to get rolling.

[sourcecode language='ruby']
begin
unless ENV['RAILS_ENV'] == ‘test’
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => ‘smtp.domain.com’,
:port => 101,
:domain => ‘domain.com’,
:authentication => :plain,
:user_name => “”,
:password => “”
}
end
end
[/sourcecode]

This way, you don’t have to explicitly set your ActionMailer::Base.delivery_method = :test in each test setup.

Tags: ,

Trackbacks/Pingbacks

  1. » Global Email Settings in Rails Available Domains: - 02. Jun, 2008

    [...] Excerpt from:Global Email Settings in Rails [...]

Leave a Reply