2

我想从 Heroku 上的 rails 应用程序发送电子邮件。由于 Heroku 不支持 SMTP,我使用外部 SMTP 服务器。

config/environments/production.rb 有以下几行。

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => 'mydomain.com',
  :port => 587,
  :user_name => "myusername",
  :password => "password",
  :authentication => :plain,
  :enable_starttls_auto => true,
  :openssl_verify_mode => 'none' 
}

当我从“heroku 运行控制台”发送电子邮件时,它工作正常。但它不会从网站发送电子邮件。奇怪的是,“heroku logs --tail”显示“Sent mail to ...”。实际上电子邮件没有发送。

有人对这个问题有任何想法吗?

谢谢。

三孔

4

3 回答 3

3

你有没有在 config/enviornment.rb 中试过这个

ActionMailer::Base.smtp_settings = {
:address => 'mydomain.com',
:port => 587,
:user_name => "myusername",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none' 
}
于 2012-08-01T09:37:48.350 回答
3

你的配置是正确的。但是你必须把它放在正确的环境文件中。在 Heroku 部署的情况下,它应该是“生产”。控制台之所以有效,是因为它使用“开发”作为环境。所以把下面的代码放在 config/environment/production.rb

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => 'mydomain.com',
  :port => 587,
  :user_name => "myusername",
  :password => "password",
  :authentication => :plain,
  :enable_starttls_auto => true,
  :openssl_verify_mode => 'none' 
}

希望它能解决你的问题。

于 2013-11-14T08:43:03.580 回答
1

如果它显示为正在发送的邮件,我建议这是您的邮件服务器上的配置问题,可能会阻止来自 Heroku IP 范围的中继——尽管它通过 heroku 控制台而不是通过您的应用程序工作,但这是最奇怪的。

您是否想过尝试使用 SendGrid Heroku 插件来缓解您自己的邮件服务器的任何问题?

于 2012-08-01T08:03:22.850 回答