rails中的ActionMailer使应用程序的每个页面都挂起

时间:2013-01-29 20:18:23

标签: ruby-on-rails actionmailer

我正在尝试使用Rails 3中内置的:mail函数发送邮件,如下所示:

  default from: "Me <me@myname.mailgun.org>"

  def gift
      mail :to => "myname@gmail.com", :subject => "test"
  end

然后我在config/initializers中有一个名为setup_mail.rb的文件:

ActionMailer::Base.smtp_settings = {
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_charset = "utf-8"
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.smtp_settings = {
       :authentication => :plain,
       :address => "smtp.mailgun.org",
       :port => 587,
       :domain => "myname.mailgun.org",
       :user_name => "postmaster@myname.mailgun.org",
       :password => "mypass"
  }
}

我添加了代码,然后重新启动了我的服务器,但应用程序无限期加载。

1 个答案:

答案 0 :(得分:2)

您不应该在初始化程序中访问config.action_mailer。删除包装ActionMailer::Base.smtp_settings块,只需将所有config.action_mailer条目更改为ActionMailer::Base

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
  :authentication => :plain,
  :address => "smtp.mailgun.org",
  :port => 587,
  :domain => "myname.mailgun.org",
  :user_name => "postmaster@myname.mailgun.org",
  :password => "mypass"
}