Rails:设计不在生产中发送确认电子邮件(Heroku)

问题描述 投票:2回答:2

我正在尝试为Heroku上的我的网站的新用户设置电子邮件确认。它在开发中工作正常(它是从正确的电子邮件发送的,即使我从未在开发中指定它.rb)

这是development.rb中的代码:(我使用的是MailCatcher)

config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {:address => "localhost", :port => 1025}

这是production.rb中的代码:

config.action_mailer.default_url_options = {:host => 'myapp.herokuapp.com'}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
   :address => "smtp.gmail.com",
   :port => 587,
   :domain => 'myapp.herokuapp.com',  #I've also tried changing this to 'gmail.com'
   :authentication => :plain, # I've also tried changing this to :login
   :enable_starttls_auto => true,
   :user_name => '[email protected]',
   :password => 'mypassword'
 }

当我在命令提示符下键入“heroku logs”时,这里是Heroku日志的最后几个(很长的列表):

2013-11-24T18:51:01.069086+00:00 app[web.1]:   Rendered layouts/_header.html.erb
(1.4ms)
2013-11-24T18:50:57.403500+00:00 heroku[router]: at=info method=GET path=/users/
confirmation/new host=myapp.herokuapp.com fwd="118.22.125.86" dyno=we
b.1 connect=30ms service=18ms status=304 bytes=0
2013-11-24T18:50:32.655624+00:00 heroku[router]: at=info method=GET path=/users/
sign_up host=myapp.herokuapp.com fwd="118.22.125.86" dyno=web.1 conne
ct=25ms service=78ms status=304 bytes=0

Heroku的生产网站只是说“我们很抱歉,但出了点问题。”电子邮件永远不会被发送。具有指定电子邮件的帐户永远不会登录到数据库中。

编辑:这是我添加config.log_level =:debug后的日志文件

2013-11-24T20:35:31.602702+00:00 heroku[router]: at=info method=GET path=/favico
n.ico host=myapp.herokuapp.com fwd="118.22.125.86" dyno=web.1 connect
=2ms service=9ms status=304 bytes=0
2013-11-24T20:35:13.963743+00:00 heroku[router]: at=info method=GET path=/favico
n.ico host=myapp.herokuapp.com fwd="118.22.125.86" dyno=web.1 connect
=1ms service=447ms status=200 bytes=0

还有一个:

2013-11-24T20:38:32.693982+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rac
k-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
2013-11-24T20:38:32.694321+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/
webrick/server.rb:295:in `block in start_thread'
2013-11-24T20:38:32.693982+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rac
k-cache-1.2/lib/rack/cache/context.rb:51:in `call'
2013-11-24T20:38:32.693982+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/
webrick/httpserver.rb:94:in `run'
2013-11-24T20:38:32.693982+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/
webrick/httpserver.rb:138:in `service'

这些只是最后几个日志。整个日志太长,无法复制到此处。我不知道该找什么。

ruby-on-rails heroku devise production confirmation
2个回答
1
投票

我对Heroku中使用Gmail的Rails应用程序进行了类似的设置。这是差异......

您的ActionMailer domain中的smtp_settings密钥不应该是必需的,因为它仅用于Google Apps for Business。尝试删除该配置变量并重新部署您的应用。

另外,我的配置没有以下内容:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true

我也建议删除这些行。

最后,我的default_url_options线有一个protocol的关键值http。因此,更改该配置也可能有所帮助:

config.action_mailer.default_url_options = {:host => 'myapp.herokuapp.com', :protocol => 'http'}

0
投票

Production.rb

  config.action_mailer.delivery_method = :smtp

  config.action_mailer.perform_deliveries = true

  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com', :protocol => 'http' }

  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            '[email protected]',
    password:             'Your gmail password',
    authentication:       'plain'
  }

第二步:转到http://www.google.com/accounts/DisplayUnlockCaptcha并单击继续。

原因:Google阻止了来自未知位置的访问。

© www.soinside.com 2019 - 2024. All rights reserved.