ruby-on-rails - 535-5.7.8 用户名和密码不被接受错误

标签 ruby-on-rails actionmailer

我在使用 action mailer 通过我的 gmail 帐户发送邮件时收到此错误。

Net::SMTPAuthenticationError in SweepstakesController#show 535-5.7.8 Username and Password not accepted.
Learn more at: ParticipantMailer.winner_confirmation(@result).deliver_now!



我已经仔细检查了我的电子邮件和密码,我已经重新启动了我的服务器,并且我已经在这里完成了与此错误相关的所有先前问题并实现了每个答案,但无济于事。
我的 development.rb 文件是:
config.action_mailer.default_url_options = { host: 'localhost', port:        3000}
ActionMailer::Base.delivery_method= :smtp
ActionMailer::Base.smtp_settings = {
  :address =>"smtp.gmail.com",
  :port => 587,
  :domain => "gmail.com",
  :user_name => "my_email@gmail.com",
  :password => "my_password",
  :authentication => 'plain',
  :openssl_verify_mode => 'none' 
}

Controller 中的逻辑:
def show
  @sweepstake = Sweepstake.find(params[:id])
  @participant = Participant.where(:sweepstake_id => @sweepstake.id )
  b = @sweepstake.winner_count
  @result = Array.new 
  b.times do 
    @result << @participant[rand(@participant.count)]
  end
  ParticipantMailer.winner_confirmation(@result).deliver_now!
end

参与者_mailer.rb 文件:
class ParticipantMailer < ApplicationMailer
  default from: 'rajesh010794@gmail.com'

  def winner_confirmation(result)
    @result = result
    @url  = 'http://example.com/login'

    Rails.logger.info(@result.inspect)
    @result.each do |i|
      mail(to: i.participant_email, subject: 'Congratulation')
    end
  end
end

最佳答案

我找到了答案 Goto config/initializers/setup_mail.rb检查那里的配置是否与development.rb文件中写入的配置匹配。 两个文件中应该如下所示:

config.action_mailer.smtp_settings = {
     :address =>"smtp.gmail.com",
     :port => 587,
     :domain => "gmail.com",
     :user_name => "my_mail@gmail.com",
     :password => "**********",
     :authentication => 'plain',
     :enable_starttls_auto => true,
     :openssl_verify_mode => 'none' 
     } 

这已经解决了我的问题。

关于ruby-on-rails - 535-5.7.8 用户名和密码不被接受错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32450382/

相关文章:

ruby-on-rails - 如何检查字符是否为utf-8

javascript - 文档加载后,某些内容滚动回 0,0

ruby-on-rails - 是否可以连接到 Linux 上的 MS Access DB?

ruby-on-rails - rails 电子邮件预览/策略指令 : "style-src ' unsafe-inline'"

ruby-on-rails - 在我的情况下如何回滚 ruby​​ on Rails

ruby-on-rails - 无法加载此类文件 -- 套接字 (LoadError)

ruby-on-rails - 带 Rails 的 ActionMailer : uninitialized constant UserMailer

ruby-on-rails - 为什么 ActionMailer (rails 2.3.5) 会开始间歇性地发送文本/html 电子邮件?

ruby-on-rails - 如何在没有模板的情况下使用 Rails 发送邮件?

ruby-on-rails - 无法在 Rails 邮件 View 中生成删除链接