我在使用 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/