【发布时间】:2018-02-23 20:35:23
【问题描述】:
我已经在线阅读了很多教程和答案,但没有找到我的解决方法。我已经将我的 ActionMailer 设置为通过 Mailgun 的服务发送电子邮件。我可以验证在生产中它确实通过我的在线联系表发送电子邮件而没有任何问题。但是,当我尝试使用 Devise 的其中一个恢复模板(即:忘记密码)时,不会发送电子邮件。
代码
--> config/environments/production.rb
# ActionMailer Config
config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'thechristianchain.org' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.mailgun.org",
:port => '587',
:domain => "mx.tccf.co",
:user_name => ENV["MAILGUN_USERNAME"],
:password => ENV["MAILGUN_PASSWORD"]
}
为了尝试调试,我将 raise_deliever_errors 设置为 true,如上面的代码所示。
当我查看日志时,我看到了这一点(我删除了日志时间戳以便于阅读):
I, [2018-02-23T20:17:28.511441 #4] INFO -- : [fb02bfdf-a5c3-4918-bae6-5c5d32ef6fba] Sent mail to info@thechristianchain.org (1028.0ms)
D, [2018-02-23T20:17:28.511562 #4] DEBUG -- : [fb02bfdf-a5c3-4918-bae6-5c5d32ef6fba] Date: Fri, 23 Feb 2018 20:17:27 +0000
From: registrations@thechristianchain.org
Reply-To: registrations@thechristianchain.org
To: info@thechristianchain.org
Message-ID: <5a9076d776379_4233fb2465758@2694484e-c3cb-44d0-8ece-832cd70adf2c.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Hello info@thechristianchain.org!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><a href="http://thechristianchain.org/password/edit?reset_password_token=1gtx9XHmTzUjf97YhJdG">Change my password</a></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
I, [2018-02-23T20:17:28.511950 #4] INFO -- : [fb02bfdf-a5c3-4918-bae6-5c5d32ef6fba] Completed 401 Unauthorized in 1044ms (ActiveRecord: 5.7ms)
F, [2018-02-23T20:17:28.513684 #4] FATAL -- : [fb02bfdf-a5c3-4918-bae6-5c5d32ef6fba]
F, [2018-02-23T20:17:28.513764 #4] FATAL -- : [fb02bfdf-a5c3-4918-bae6-5c5d32ef6fba] Net::SMTPAuthenticationError (535 5.7.0 Mailgun is not loving your login or password
):
密钥在最后一行失败,因为401 Unauthorized 和Net::SMTPAuthenticationError 基本上说明Mailgun 不喜欢我的登录凭据。
问题
这是我的问题。设计从哪里获取信息?当我通过联系表发送邮件时,Mailgun 接受我提交的登录凭据;但是当 Devise 发送时,它们不被接受。这让我觉得有些地方没有从production.rb 中提取信息。
【问题讨论】:
-
尝试将环境变量更改为
:user_name => ENV.fetch("MAILGUN_USERNAME"), :password => ENV.fetch("MAILGUN_PASSWORD")。这没有用。同样的错误。 -
您查看过 Mailgun 文档吗?我从未使用过 gem,但它似乎对带有 API 密钥设置等的
production.rb设置显示了非常不同的使用风格。 -
没错,我使用的是他们的 API 而不是 SMTP 调用。他们建议这样做,因为它更快。但是,也许 Devise gem 不能使用它。我会检查一下,看看是不是这个原因。
标签: ruby-on-rails devise actionmailer