为什么我在开发模式下使用SendGrid SMTP Relay从我的Heroku Rails应用程序发送的收件箱中看不到任何电子邮件?

时间:2017-07-24 20:16:30

标签: ruby-on-rails heroku smtp development-environment sendgrid

我正在尝试通过SendGrid的SMTP Relay从我的Rails 4.2应用程序中的Mandrill切换到SendGrid。我已将“收件人电子邮件”设置为我的个人电子邮件地址,以便我可以查看已发送的电子邮件,但是,尽管rails控制台声称已经处理并发送了电子邮件,但实际上没有任何电子邮件显示在我的收件箱中。 / p>

我相当确定我的所有邮件都有适当的smtp设置,因为我大多数都遵循SendGrid网站上提供的说明:https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html

我还通过telnet测试了我与SendGrid的SMTP中继的连接,并且连接成功。

我的SendGrid信息中心表示已发送了0封电子邮件。我的所有电子邮件都不会显示在“撤消”标签下,因此它们不会被退回或被阻止。

这是在我的config / environment.rb中:

ActionMailer::Base.smtp_settings = {
:user_name => 'apikey',
:password => ENV['SENDGRID_API_KEY'],
:domain => 'heroku.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}

这是在我的config / environments / development.rb中:

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net' }

这是我的控制器中调用我的ApplicationMailer的行:

ApplicationMailer.send_email(user, 'mypersonalemail@email.com', 'Test Subject').deliver

这是执行邮件程序方法时在控制台中打印的内容:

ApplicationMailer#send_email: processed outbound mail in 789.9ms
Sent mail to mypersonalemail@email.com (103.4ms)

但我的收件箱或垃圾邮件文件夹中仍然没有收到任何电子邮件。有谁知道我怎么解决这个问题?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您的域名和主机选项有误。使用localhost:3000(除非您使用docker或其他东西替换localhost:3000和0.0.0.0:8000)

#/environments/development.rb
  #Mailer Options
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'localhost:3000',
    :enable_starttls_auto => true
  }
  config.action_mailer.default_url_options = { host: 'http://localhost:3000' }
  config.action_mailer.asset_host = 'http://localhost:3000'

确保将sendgrid凭据作为环境变量添加到本地计算机。要获取它们,请转到您的heroku应用程序并单击设置,然后"显示配置变量"。然后将这些sendgrid凭据作为env添加到本地计算机。 vars,你已经完成了。

相关问题