【问题标题】:SendGrid not sending emails HerokuSendGrid 不发送电子邮件 Heroku
【发布时间】:2018-10-22 15:02:14
【问题描述】:

我正在尝试使用我的 Rails 应用程序中的 SendGrid 发送邮件(使用 Hartl 的教程)。仅仅使用 Heroku 的插件是行不通的,因为它需要我的信用卡。然后我在 SendGrid 上注册并使用我的凭据,但仍然没有邮件。上面是我的 production.rb 文件。请帮忙?

  config.action_mailer.delivery_method = :smtp
  host = '<https://nameless-sierra-13544>.herokuapp.com'
  config.action_mailer.default_url_options = { host: host }
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['myusername'],
    :password       => ENV['mypass#'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }

谢谢,

【问题讨论】:

  • 您的host 值是否包含&lt;&gt;?为什么:domain 设置为'heroku.com'?那不应该是您应用的完整域吗?
  • 你解决过这个问题吗?
  • @Rockwell Rice,实际上没有,我听从了你的建议,但没有奏效,也许问题出在代码的其他地方,我无法弄清楚。
  • 你在 heroku 中设置了所有的 ENV 变量,对吗?
  • 我一开始当然没有,现在它可以用于开发。我加密了我的 gmail 凭据(使用:rails credentials:edit)并且变量设置正确。

标签: ruby-on-rails heroku sendgrid


【解决方案1】:

根据上面的评论,我相信你的价值观有点偏离。我也相信您需要设置一个from 地址。这是我在生产中使用的内容的副本,其中包含您的价值观,它有效,因此希望这会有所帮助。我确实相信缺少有效的from 地址和域值中的字符是这不起作用的原因。当然,还要确保你在 heroku 上设置了 ENV 变量。

生产.rb

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { host:'https://nameless-sierra-13544.herokuapp.com' }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"
  ActionMailer::Base.smtp_settings = {
    :from                 => 'your_email_here@email.com',
    :user_name            => ENV['myusername'],
    :password             => ENV['mypass#'],
    :domain               => 'https://nameless-sierra-13544.herokuapp.com',
    :address              => 'smtp.sendgrid.net',
    :port                 => 587,
    :authentication       => :plain,
    :enable_starttls_auto => true
  }

【讨论】:

  • 主机和域不应该一样吗?
  • 你是 100% 正确的。输入代码时我忘记更新了。
猜你喜欢
  • 2018-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
  • 2014-09-09
  • 2018-11-08
相关资源
最近更新 更多