Rails:Devise未在生产环境中发送确认电子邮件(Heroku) [英] Rails: Devise not sending confirmation email in production (Heroku)

查看:75
本文介绍了Rails:Devise未在生产环境中发送确认电子邮件(Heroku)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to set up email confirmation for new users for my site on Heroku. It works fine in development (it's sent from the correct email, even though I never specified it in development.rb)

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

Here is the code in development.rb: (I was using 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中的代码:

Here is the code in 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 => 'mygmailaccount@gmail.com',
   :password => 'mypassword'
 }

这是在命令提示符下键入"heroku logs"时,Heroku日志中的最后几个(非常长的列表):

And here are the last few (of a very long list of) Heroku logs when I type "heroku logs" in the command prompt:

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上的生产站点只说:很抱歉,但是出了点问题."电子邮件永远不会发送.具有指定电子邮件的帐户永远不会登录到数据库.

The production site on Heroku just says "We're sorry, but something went wrong." The email never gets sent. The account with the specified email is never logged into the database.

这是我添加config.log_level =:debug

Here are the log files after I added 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'

这些只是最后几条日志.整个日志太长,无法在此处复制.我不确定要寻找什么.

These are only the last few logs. The entire log is too long to copy on here. I'm not sure what to be looking for.

推荐答案

我在Heroku中使用Gmail的Rails应用程序具有类似的设置.这就是区别...

I have a similar setup for a Rails app in Heroku that uses Gmail. Here's the differences...

您不需要ActionMailer smtp_settings 中的 domain 键,因为该键仅用于Google Apps for Business.尝试删除该配置变量,然后重新部署您的应用.

The domain key in you ActionMailer smtp_settings shouldn't be necessary as that is only used for Google Apps for Business. Try removing that config variable and re-deploying your app.

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

Also, my config doesn't have the following:

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

我也建议删除这些行.

最后,我的 default_url_options 行有一个 protocol 密钥,其值是 http .因此,更改该配置也可能会有所帮助:

Finally, my default_url_options line has a key of protocol with a value of http. So, changing that config may help as well:

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

这篇关于Rails:Devise未在生产环境中发送确认电子邮件(Heroku)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆