【问题标题】:Email for user confirmation not sending in production. Rails, Heroku, Devise, Gmail用于用户确认的电子邮件未在生产中发送。 Rails、Heroku、Devise、Gmail
【发布时间】:2013-12-09 21:43:41
【问题描述】:

我在 Google 和 stackoverflow 上都找过答案,但都没有。 我正在尝试设置 smtp 电子邮件以在注册后进行用户确认。它在开发中运行良好。即使启用了 MailCatcher,它也会以某种方式绕过它并从我指定的 gmail 发送到正确的电子邮件。

这是 development.rb 中的内容:

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', :protocol => 'http'} #I've also tried it without ":protocol => 'http'"
 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,
     :authentication => :plain,   # I've also tried :login
     :enable_starttls_auto => true,  # Also tried tls => true
     :user_name => 'myemail@gmail.com',
     :password => 'mypassword'
   } #I've also tried having the attribute :domain => 'myapp.herokuapp.com',

在 config/initializers/devise.rb 中

config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'  #It still sends from myemail@gmail.com even with this line uncommented.

我不知道如何将整个 7 页(word 文档)的 heroku 日志粘贴到代码块中,所以我将它们粘贴到了谷歌文档中。

heroku 日志的谷歌文档(我相信我在第 1-2 页强调了它开始出错的部分):

https://docs.google.com/document/d/1G-cCX7T1sPL5XtjyjHRaWmzfaBbWkuTR2edsDmDm1Pc/edit?usp=sharing

我不确定它在哪里可以找到正确的电子邮件以在开发中发送。我还是个新手。

edit:我刚刚发现在添加确认之前注册的用户也无法登录,所以这可能是heroku的用户问题。但在开发过程中一切仍然正常。

非常感谢您的帮助,谢谢!

【问题讨论】:

    标签: ruby-on-rails email heroku devise confirmation


    【解决方案1】:

    你可能会错过这个config.action_mailer.perform_deliveries = true

    【讨论】:

    • 我之前在 production.rb 文件中有这个,但当我被告知不需要它时将其删除。
    • 我在您的日志中找不到任何错误消息,我认为它被切断了。
    • 另外,我在使用 Gmail 时遇到了问题,我不得不接受外部访问权限(当您登录 Gmail 时,顶部会显示一条消息)。否则,您将遇到 SMTPAuthenticationError。 check it out
    • 我从未在我的 Gmail 顶部收到消息/警告。我还检查了上次登录的详细信息,它显示它是在开发中通过 SMTP 登录的,但是在我尝试生产时它没有登录。如果 heroku 日志没有显示错误消息,我该如何找到它?
    • stackoverflow.com/a/6766529/1881153 这可能会帮助您了解 Heroku 日志级别。
    【解决方案2】:

    请检查您的 gmail 是否要求验证码以发送邮件。并调试错误请在您的 production.rb 上创建config.action_mailer.raise_delivery_errors = true。请检查类似的问题Net::SMTPAuthenticationError when sending email from Rails app (on staging environment)

    【讨论】:

    • 我检查了页面并确保我的代码反映了他们的解决方案。我还检查了验证码。谷歌说:“帐户访问已启用请尝试从您的新设备或应用程序再次登录您的谷歌帐户。”它仍然无法正常工作。
    • 另外,既然它在开发中工作(因为它实际上是从 gmail 发送的),它在生产中会有所不同吗?
    • 是的,有时它会在生产中产生问题。正如谷歌要求验证码。请按照上一个链接,并检查发送电子邮件有什么错误
    • Gmail 说已启用对该帐户的访问。如何检查有什么错误?在 Heroku 上,它只是说“我们很抱歉,但出了点问题。”
    • heroku 日志上传到 speedyshare。我在原始帖子中链接到它。我不确定如何粘贴长行代码而不必在每行之前手动键入 4 个空格。如果您担心这是恶意下载,我可以将其放在 google doc 中。
    猜你喜欢
    • 2019-02-16
    • 2013-12-09
    • 2019-12-12
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多