我正在为我的应用程序实现设计邮件程序,我已完成以下步骤:
在模型中:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
end
然后我添加了confirmation_token、confirmation_at、的迁移, confirmation_sent_at
在 devise.rb 中,我添加了:
config.mailer_sender = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="55302d3438253930153238343c397b363a38" rel="noreferrer noopener nofollow">[email protected]</a>'
config.mailer = 'Devise::Mailer'
开发中.rb:
config.assets.raise_runtime_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
authentication: :plain,
user_name: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="25405d4448554940654248444c490b464a48" rel="noreferrer noopener nofollow">[email protected]</a>',
password: 'example@123',
enable_starttls_auto: true,
openssl_verify_mode: 'none'
}
我的所有凭据都很好。但电子邮件并未生成。 在我的控制台中,我收到邮件信息和链接..
我的控制台:
Sent mail to <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b3e233a362b373e1b223a33343475383436" rel="noreferrer noopener nofollow">[email protected]</a> (2597.8ms)
Date: Wed, 08 Apr 2015 23:39:09 +0530
From: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="07627f666a776b6247606a666e6b2964686a" rel="noreferrer noopener nofollow">[email protected]</a>
Reply-To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="35504d5458455950755258545c591b565a58" rel="noreferrer noopener nofollow">[email protected]</a>
To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2c7dac3cfd2cec7e2dbc3cacdcd8cc1cdcf" rel="noreferrer noopener nofollow">[email protected]</a>
Message-ID: <55256ec5ba47e_26f51d984dc117aa@itadmin-HP-Pavilion-17-Notebook-PC.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Hello <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9acb1a4b9a5ac89b0a8a1a6a6e7aaa6a4" rel="noreferrer noopener nofollow">[email protected]</a>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><a href="http://localhost:3000/users/password/edit?reset_password_token=M5os3tBYHQrsRaw4TtTt">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>
我还没有添加任何设备密码 Controller /注册 Controller 。
我可能遇到什么问题?
最佳答案
您必须在 development.rb
文件中添加这行代码:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { host: 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
authentication: :plain,
user_name: '****@gmail.com',
password: '*****',
openssl_verify_mode: 'none'
}
关于ruby-on-rails - 无法使用 devise Rails 接收电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29529379/