3
votes

I'm trying to setup e-mail actions in my Rails app and I want to test the mailing functions locally. I followed this Railscast but sending mail throws a Timeout::Error(execution expired) error whenever I attempt to send mail.

config/environments/development.rb

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address              => 'smtp.gmail.com',
  :port                 => 587,
  :domain               => 'recipes.dev',
  :user_name            => '[email protected]',
  :password             => '*******',
  :authentication       => 'plain',
  :enable_starttls_auto => true
}

mailers/user_mailer.rb

class UserMailer < ActionMailer::Base
  default from: "[email protected]"

  def test_email(user)
    @email = user.email
    @name = user.name
    mail(:to => @email, :subject => 'test e-mail')
  end
end

controllers/users_controller.rb

UserMailer.test_email(@user).deliver

Any help would be appreciated.

1

1 Answers

0
votes

Try putting your smpt_setting side development.rb as:

config.action_mailer.smtp_settings = {
  :address              => 'smtp.gmail.com',
  :port                 => 587,
  :domain               => 'recipes.dev',
  :user_name            => '[email protected]',
  :password             => '*******',
  :authentication       => 'plain',
  :enable_starttls_auto => true
}

you don't need setup_mail.rb

please look at http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration