我是 Rails 的完整初学者,我正在尝试在有人使用 Action Mailer 注册后发送电子邮件。
我的日志说电子邮件正在发送,但 Gmail 从来没有收到它。
配置/初始化程序/setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "asciicasts.com",
:user_name => "asciicasts",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
邮件程序/user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "eifion@asciicasts.com"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Registered")
end
end
控制器/users_controller.rb
...
def create
@user = User.new(params[:user])
if @user.save
UserMailer.registration_confirmation(@user).deliver
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
...
谢谢!