我在Rails中是完整的初学者,我试图在有人使用actionmailer注册后发送电子邮件.
我的日志说电子邮件正在发送,但是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 ...
谢谢!
解决方法
确保您的config / environments / development.rb中设置了此选项:
config.action_mailer.delivery_method =:smtp
另外,在ActionMailer :: Base.smtp_settings中,您需要指定一个有效的Gmail帐户.复制粘贴(asciicasts)不会在这里剪切.
看这个问题供参考:Sending mail with Rails 3 in development environment