0

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

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

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

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

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"
  }
}

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

4

1 回答 1

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"
}
于 2013-01-29T20:32:37.043 回答