我对 Rails 很陌生。现在我在 Rails 网站上发送重置密码电子邮件时遇到问题。
现在的问题是当我输入一个注册的电子邮件来重置密码时,电子邮件无法发送。
PasswordResetsController#create 中的 Net::OpenTimeout
我认为问题在于 stmp 设置。
这是我的一些代码。顺便说一句,我在开发环境中做所有这些。
发展.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host =>
"http://localhost:3000" }
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "Here I put my intern company",
# :domain => "gmail.com",
:authentication => :plain,
:user_name => "Here I put my actual email",
:password => "The password of my actual email",
:enable_starttls_auto => true
}
密码重置控制器.rb
def create
# @user = User.find_by(email: params[:password_resets]
[:email].downcase)
@user = User.find_by(email: params[:password_reset]
[:email].downcase)
if @user
@user.create_reset_digest
@user.send_password_reset_email
flash[:info] = "Email sent with password reset instructions"
redirect_to root_url
else
flash.now[:danger] = "Email address not found"
render 'new'
end
end
用户.rb
def send_password_reset_email
UserMailer.password_reset(self).deliver_now
end
user_mailer.rb
class UserMailer < ApplicationMailer
default from: "naomi<noreply@MYINTERNCOMPANY.com>"
def password_reset(user)
@user = user
mail(to: @user.email, subject: 'Password reset')
end
end
application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: 'noreply@MYINTERNCOMPANY.com'
layout 'mailer'
end
有人能帮忙吗?
另外,在此之后我该如何设置生产环境,以便网站可以部署在 Heroku 上?