ruby-on-rails – rails,action mailer不发送

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – rails,action mailer不发送前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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

原文链接:https://www.f2er.com/ruby/267231.html

猜你在找的Ruby相关文章