Rails:Net::SMTPAuthenticationError(535 身份验证失败:用户名/密码错误)

2023-12-23

我正在尝试在 Rails 应用程序中设置电子邮件,但收到错误“Net::SMTPAuthenticationError (535 身份验证失败:用户名/密码错误 )”当我在生产环境中触发邮件操作时。

控制器:

class FeedbacksController < InheritedResources::Base

    def create
        @feedback = Feedback.new(feedback_params)
        @user = current_user
         respond_to do |format|
            if @feedback.save
              ExampleMailer.sample_email(@user).deliver

              format.html { redirect_to @feedback, notice: 'feedback was successfully created.' }
              format.json { render :show, status: :created, location: @user }
            else
              format.html { render :new }
            end
        end
    end
end

配置/环境/生产.rb:

 config.action_mailer.default_url_options = { :host => 'myurl.com:4321' }
  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
   :address              => "smtp.gmail.com",
   :port                 => 587,
   :domain               => "myurl.com:4321",
   :user_name            => "[email protected] /cdn-cgi/l/email-protection",
   :password             => "mypassword",
   :authentication       => "plain",
   :enable_starttls_auto => true
  }

example_mailer.rb:

class ExampleMailer < ActionMailer::Base
  default from: "[email protected] /cdn-cgi/l/email-protection
  def sample_email(user)
    @user = user
    mail(to: @user.email, subject: 'sample email')
  end
end

您的邮件中存在拼写错误:

class ExampleMailer < ActionMailer::Base
  default from: "[email protected] /cdn-cgi/l/email-protection"
  def sample_email(user)
    @user = user
    mail(to: @user.email, subject: 'sample email')
  end
end

而在你的production.rb,您可以将用户名写为myemail。没关系。

如果不起作用请告诉我..

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails:Net::SMTPAuthenticationError(535 身份验证失败:用户名/密码错误) 的相关文章

随机推荐