Timeout ::在本地服务器上使用ActionMailer时出错

时间:2012-06-21 16:46:38

标签: ruby-on-rails ruby ruby-on-rails-3 email actionmailer

我正在尝试在我的Rails应用程序中设置电子邮件操作,我想在本地测试邮件功能。我跟着this Railscast但是每当我尝试发送邮件时,发送邮件都会抛出Timeout::Error(execution expired)错误。

配置/环境/ development.rb

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

配置/初始化/为setup_mail.rb

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

寄件人/ user_mailer.rb

class UserMailer < ActionMailer::Base
  default from: "myemail@gmail.com"

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

控制器/ users_controller.rb

UserMailer.test_email(@user).deliver

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

尝试将您的smpt_setting side development.rb设置为:

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

您不需要setup_mail.rb

请查看http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration