邮件错误 Gmail Net::SMTPAuthenticationError in EnglishGradesController#create

Mailer error Gmail Net::SMTPAuthenticationError in EnglishGradesController#create

我正在尝试在我的 rails 应用程序中创建新的英语成绩时发送电子邮件。在此应用程序中,学生是继承 (STI) 类型的设计用户可能是相关的,我正试图在教师(另一种类型的继承设计用户)创建成绩时向他们发送电子邮件。

目前正尝试使用 gmail 在本地运行它。我用了

rails g mailer UserMailer

进行设置。

这是我在创建英语成绩时遇到的错误。

Net::SMTPAuthenticationError in EnglishGradesController#create

530-5.5.1 需要身份验证。在

了解更多信息
@student = Student.find_by_id(@english_grade.student_id)
  if @english_grade.save
    **UserMailer.new_grade(@student).deliver**
    redirect_to(student_path(@student), :notice => "Post was successfully created.")
  else // etc

(** 是突出显示的错误)

上面也是我调用邮件的地方,所以我不再重复。

我的 development.rb 文件:

config.action_mailer.raise_delivery_errors = true

config.action_mailer.delivery_method = :smtp

config.action_mailer.default_url_options = { :host => "my ip address" }

config.action_mailer.smtp_settings = {
 :address              => "smtp.gmail.com",
 :domain => 'my ip address:3000', //where 3000 is the port I'm running on locally
 :port                 => 587,
 :user_name            => ENV['example@gmail.com'],
 :password             => ENV['password'],
 :authentication       => "plain",
:enable_starttls_auto => true
}

  config.action_mailer.perform_caching = false

我的邮件:

class UserMailer < ApplicationMailer
default from: "example@gmail.com"

  def new_grade(user)
    @user = user
    mail to: @user.email, subject: "New grade created"
  end

end

来自阅读其他一些问题:

在 development.rb 我试过没有 'domain:' 并且没有主机 IP 地址

我试过: http://www.google.com/accounts/DisplayUnlockCaptcha

我还允许访问安全性较低的应用程序 https://www.google.com/settings/security/lesssecureapps

我把密码改得比较复杂

我也试过将端口更改为 465,但出现文件结束错误。

此外,如果它有任何相关性,我今天创建了这个 gmail 帐户,专门为该应用程序发送电子邮件

非常感谢任何帮助,谢谢!

问题实际上是

 :authentication       => "plain",

需要:

 :authentication       => "login",