我正在为我的应用程序实现设计邮件程序,我已完成以下步骤:
模特中的:
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,confirmed_at的迁移, confirmation_sent_at
在devise.rb中,我补充道:
config.mailer_sender = 'example@gmail.com'
#config.mailer = 'Devise::Mailer'
在development.rb中:
config.assets.raise_runtime_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,
:domain => "mail.google.com",
:user_name => "example@gmail.com",
:password => "somepassword",
:enable_starttls_auto => true
}
一切正常。但是没有生成电子邮件。
在我的控制台中,我收到邮件信息和链接..
我的控制台:
Sent mail to example@yahoo.com (2597.8ms)
Date: Wed, 08 Apr 2015 23:39:09 +0530
From: example@gmail.com
Reply-To: example@gmail.com
To: example@yahoo.com
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 exmple@yahoo.com!</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>
我还没有添加任何设备密码控制器/ registartion控制器。 当我点击忘记密码并输入电子邮件并点击“发送重置密码说明”按钮时出现错误。 这是错误,我得到了:
Devise中的Net :: SMTPAuthenticationError :: PasswordsController #create
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsrrD
-
我使用Running into SMTP error when trying to send email in RoR app但没有帮助我。 我可能会遇到什么问题?
答案 0 :(得分:5)
在谷歌检查了一些选项后,这个选项正常工作
点击https://www.google.com/settings/u/0/security/lesssecureapps
使用您在smtp配置中提供的电子邮件地址登录,从而启用对安全性较低的应用的访问权限。
答案 1 :(得分:0)
登录您的Google帐户,找到&#34;允许安全性较低的应用&#34;并将其打开。