【发布时间】:2015-08-25 18:59:47
【问题描述】:
首先,让我指定我知道 ActionMailer 在开发模式下默认不发送电子邮件。
另外,我查看了类似的问题,但没有一个与我的情况有关。
那么,我们开始吧:
我从 2015 年 3 月 26 日起关注 Ilya Bodrov-Krukowski 的 this Site Point tutorial,以便在我的 Rails 4 应用程序上安装和设置 Devise。
因为我们激活了 Devise 的
confirmable模块,所以我需要在开发中发送电子邮件,以允许注册的用户激活他们的帐户并登录。每当我创建一个新用户(通过
http://localhost:3000/users/sign_up)时,我都会收到以下警报:
带有确认链接的消息已发送到您的电子邮件 地址。请点击链接激活您的帐户。
- 但是,我实际上从未收到带有确认链接的电子邮件。
—————————
更新
在我的 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)
而且,当我将日志中的链接复制并粘贴到浏览器中时,我会收到以下警报:
登录成功。
因此,似乎唯一不起作用的是电子邮件的实际发送/接收。
—————————
按照教程中的建议,我遵循了有关 ActionMailer configuration 的 Rails 文档,这是我在 config/environments/development.rb file 中的内容:
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 非常非常初级)。
有什么想法吗?
【问题讨论】:
-
你用的是什么邮件服务器?
-
非常好的问题。我如何/在哪里可以获得这些信息? (也许这是我的问题:我认为我没有设置邮件服务器)。
-
试试mailcatcher。它使处理开发中的电子邮件不再是 PITA。
-
您指定的
config.action_mailer.delivery_method是什么? -
感谢您的提示。有没有办法让电子邮件在不使用第三方解决方案的情况下在开发模式下工作(即仅使用 Rails 默认配置选项)?
标签: ruby-on-rails ruby-on-rails-4 devise actionmailer devise-confirmable