rails中的smtp设置在本地工作但不在生产中

时间:2017-02-03 21:55:22

标签: ruby-on-rails actionmailer

我正在Rails中构建联系表单。我正在使用gmail发送消息。它在开发中非常有效,但在生产中却没有。 Heroku给了我这个错误:

2017-02-03T21:47:02.629544+00:00 app[web.1]: I, [2017-02-03T21:47:02.629450 #4]  INFO -- : [082aab82-7b98-45b4-97da-b92470134ef8] Completed 500 Internal Server Error in 731ms (ActiveRecord: 0.0ms)
2017-02-03T21:47:02.630122+00:00 app[web.1]: F, [2017-02-03T21:47:02.630063 #4] FATAL -- : [082aab82-7b98-45b4-97da-b92470134ef8]   
2017-02-03T21:47:02.630180+00:00 app[web.1]: F, [2017-02-03T21:47:02.630122 #4] FATAL -- : [082aab82-7b98-45b4-97da-b92470134ef8] Net::SMTPAuthenticationError (534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsT

这似乎表明我的smtp设置有问题。这是我的生产环境中的设置。有人可以帮忙吗?

config.action_mailer.raise_delivery_errors = true

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:user_name => "myeamil@gmail.com",
:password => "mypassword",
:authentication => "plain",
:enable_starttls_auto => true
} 

1 个答案:

答案 0 :(得分:0)

尝试在heroku上使用'SENDGRID'插件。

只需在heroku应用中的资源标签中添加sendgrid插件,您的production.rb文件中的设置如下:

config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings= { 
    :user_name => ENV['SENDGRID_USERNAME'],
    :password => ENV['SENDGRID_PASSWORD'],
    :domain => 'gmail.com',
    :address => 'smtp.sendgrid.net',
    :port => 587,
    :authentication => :plain,
    :enable_starttls_auto => true
  }