【问题标题】:Sending emails on Heroku using external SMTP使用外部 SMTP 在 Heroku 上发送电子邮件
【发布时间】:2012-07-30 02:20:01
【问题描述】:

我想从 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 ...”。实际上邮件没有送达。

有人知道这个问题吗?

谢谢。

三江

【问题讨论】:

    标签: ruby-on-rails heroku smtp


    【解决方案1】:

    你在 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' 
    }
    

    【讨论】:

    • 这行得通!奇怪... Heroku 处理 production.rb 和 environment.rb 的方式不同。非常感谢。
    【解决方案2】:

    您的配置是正确的。但是你必须把它放在正确的环境文件中。在 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' 
    }
    

    希望它能解决您的问题。

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 好建议。我会将它用于少量电子邮件。
      猜你喜欢
      • 2019-05-27
      • 2016-07-14
      • 2010-12-02
      • 2014-12-24
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      相关资源
      最近更新 更多