首先,让我说明一下,我知道 ActionMailer 在开发模式下默认不发送电子邮件。
另外,我看了类似的问题,没有一个与我的情况相关。
那么,我们开始吧:
我正在关注 this Site Point tutorial由 Ilya Bodrov-Krukowski 从 2015 年 3 月 26 日起在我的 Rails 4 应用程序上安装和设置 Devise。
因为我们激活了 Devise 的
confirmable
模块,我需要在开发中发送电子邮件以允许注册的用户激活他们的帐户并登录。每当我创建新用户(通过
http://localhost:3000/users/sign_up
)时,我都会收到以下警报:
A message with a confirmation link has been sent to your email address. Please follow the link to activate your account.
- 但是,我实际上从未收到过带有确认链接的电子邮件。
————————————
更新
在我的 development.log 文件中,我可以看到电子邮件已“发送”:
Devise::Mailer#confirmation_instructions: processed outbound mail in 172.1ms
Sent mail to hello@mydomain.com (54.4ms)
Date: Tue, 25 Aug 2015 12:15:15 -0700
From: contact@anotherdomain.com
Reply-To: contact@anotherdomain.com
To: hello@mydomain.com
Message-ID: <55dcbec3a1ef8_33b93fcffc4988f493685@XXXXXX.local.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Welcome hello@mydomain.com!</p>
<p>You can confirm your account email through the link below:</p>
<p><a href="http://localhost:3000/users/confirmation?confirmation_token=ZsL_iQVxfDQd7mB1RkGf">Confirm my account</a></p>
[1m[35m (0.8ms)[0m commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 560ms (ActiveRecord: 1.7ms)
并且,当我将日志中的链接复制并粘贴到我的浏览器中时,我会收到以下警告:
Signed in successfully.
因此,似乎唯一不起作用的是电子邮件的实际发送/接收。
————————————
按照教程中的建议,我遵循了有关 ActionMailer configuration 的 Rails 文档这是我的 config/environments/development.rb 文件
中的内容:
config.action_mailer.delivery_method = :sendmail
# Defaults to:
# config.action_mailer.sendmail_settings = {
# location: '/usr/sbin/sendmail',
# arguments: '-i -t'
# }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'hello@mydomain.com'}
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
显然,我遗漏了一些东西,但我不知道是什么(我对 Rails 非常非常初级)。
有什么想法吗?
最佳答案
开发中默认不发送邮件。要启用此功能,您必须在 development.rb
文件中设置 config.action_mailer.perform_deliveries = true
,我看到您已经拥有该文件。
您可能还必须启用 config.action_mailer.raise_delivery_errors = true
以引发投递错误。这样,您将能够查看电子邮件发送过程中是否存在任何错误。
此外,仔细检查您的默认发件人
是否有有效的电子邮件。
也可以尝试将发送方式切换为 sendmail
:
config.action_mailer.delivery_method = :sendmail
这应该可以解决您的问题。
关于ruby-on-rails - Rails 4 ActionMailer 不在开发模式下发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32211964/