Sending mail with Rails 3 in development environment

Solution 1:

Well I have resolved the issue, but quite why this works and the other methods did not, I don't know.

The solution was to create an initialiser in config/initialisers/setup_mail.rb containing the following

if Rails.env != 'test'
  email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/email.yml"))
  ActionMailer::Base.smtp_settings = email_settings[Rails.env] unless email_settings[Rails.env].nil?
end

I then added config/email.yml containing the details of the dev and production email accounts

development:
  :address: smtp.gmail.com
  :port: 587
  :authentication: plain
  :user_name: xxx
  :password: yyy
  :enable_starttls_auto: true
production:
  :address: smtp.gmail.com
  :port: 587
  :authentication: plain
  :user_name: xxx
  :password: yyy
  :enable_starttls_auto: true

Like I say, no idea why, but this seemed to do the trick. Thanks all for the pointers

Solution 2:

I have the following in config/environments/development.rb

config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true

The actual mail-configuration, config.actionmailer.* i have placed in config\application.rb.

Hope this helps :)

Solution 3:

Try using 'sendmail' instead of 'smtp'.

ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.sendmail_settings = {
  :address              => "smtp.gmail.com",
  :port                 => "587",
  :domain               => "gmail.com",
  :user_name            => "[email protected]",
  :password             => "yyy",
  :authentication       => "plain",
  :enable_starttls_auto => true
}