我正在关注这个 railscast 以熟悉 Rails 3 中的 ActionMailer,但我没有运气让电子邮件送达。
我在想我的问题可能与我的 setup_mail.rb 文件有关,有人可以在这里发现问题吗?我正在尝试从我的 gmail 帐户 jbdyno@gmail.com 发送电子邮件
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
}
其他文件
user_mailer.rb
class UserMailer < ActionMailer::Base
default from: "jbdyno@gmail.com"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Registered")
end
end
registration_confirmation.text.erb
Thanks for registering!
users_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
谢谢!!!