邮件不发送动作邮件铁路

时间:2016-07-14 09:56:00

标签: ruby-on-rails ruby email ruby-on-rails-4

我正在尝试通过rails中的动作邮件程序实现发送邮件 相关代码是......

development.rb

 config.action_mailer.default_url_options = { host: 'localhost', port: 9292}

 config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
   :address     =>"smtp.gmail.com",
    :domain      =>"gmail.com",
   :port        => 587,
   :user_name   =>"Debasis",
   :password    =>"************",
   :authentication =>"plain",
   :enable_starttls_auto =>true
   }

my mailers / user_mailer.rb

class UserMailer < ActionMailer::Base
    default :from => "bkdebasish90@gamil.com"
    def registration_confirmation(user)
    mail(:to=>user.email, :subject =>"Registered")
   end
end

users.controller是

  def create
   @user = User.new(user_params)
   respond_to do |format| 
if @user.save
  UserMailer.registration_confirmation(@user).deliver_now
  format.html { redirect_to @user, notice: 'User was successfully created.'       
}
  format.json { render :show, status: :created, location: @user }
     else
  format.html { render :new }
  format.json { render json: @user.errors, status: :unprocessable_entity }
    end
     end
    end  

但是我的电子邮件没有发送......我该怎么办?

1 个答案:

答案 0 :(得分:0)

我发现您使用的是Gmail,因此假设您使用的是双因素身份验证,则需要创建一个特定于应用的密码才能输入配置,而不是您自己的密码。

尝试在开发环境文件中设置config.action_mailer.raise_delivery_errors = true以查看发生的任何错误

相关问题