Ruby on rails Rails 3邮件问题
我跟随railscast是为了熟悉Rails3中的ActionMailer,但是我没有幸收到要发送的电子邮件 我想我的问题可能是我的setup_mail.rb文件,有人能在这里发现问题吗?我正在尝试从我的gmail帐户中获取要发送的电子邮件jbdyno@gmail.comRuby on rails Rails 3邮件问题,ruby-on-rails,email,actionmailer,Ruby On Rails,Email,Actionmailer,我跟随railscast是为了熟悉Rails3中的ActionMailer,但是我没有幸收到要发送的电子邮件 我想我的问题可能是我的setup_mail.rb文件,有人能在这里发现问题吗?我正在尝试从我的gmail帐户中获取要发送的电子邮件jbdyno@gmail.com ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port =>
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "jbdyno",
:password => "I PUT MY PASSWORD HERE",
:authentication => "plain",
:enable_starttls_auto => true
}
其他文件 用户_mailer.rb
class UserMailer < ActionMailer::Base
default from: "jbdyno@gmail.com"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Registered")
end
end
用户\u controller.rb
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
UserMailer.registration_confirmation(@user).deliver
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render json: @user, status: :created, location: @user }
else
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
谢谢 在您试图发送电子邮件的环境的配置中,您可能需要添加
config.action\u mailer.delivery\u method=:smtp
有关使用gmail配置的完整示例,请参阅
确保在更改配置文件后重新启动开发服务器。您所做的第一眼看上去很好。您的日志中是否有任何传递错误或提示可能发生的情况?您是否在尝试发送电子邮件的环境中设置了
config.action\u mailer.delivery\u method=:smtp
?(请参阅Rails指南,其中包含gmail的特定设置)。旁注:要在开发中显示电子邮件,RailsCasts的创建者Ryan Bates提出了一个很好的建议。我在我的config/environments/development.rb文件中添加了“config.action\u mailer.delivery\u method=:smtp”,但运气不好。我没有收到任何错误,新用户正在添加到数据库中,只是没有电子邮件。您应该在您的环境配置中设置config.action\u mailer.raise\u delivery\u errors=true
,以查看是否会在日志中出现错误。
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
UserMailer.registration_confirmation(@user).deliver
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render json: @user, status: :created, location: @user }
else
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end