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

时间:2015-02-12 08:20:38

标签: ruby-on-rails smtp actionmailer

我正在尝试在我的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

配置/环境/ production.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            => "myemail@gmail.com",
   :password             => "mypassword",
   :authentication       => "plain",
   :enable_starttls_auto => true
  }

example_mailer.rb:

class ExampleMailer < ActionMailer::Base
  default from: "myemail@gmail.com
  def sample_email(user)
    @user = user
    mail(to: @user.email, subject: 'sample email')
  end
end

1 个答案:

答案 0 :(得分:0)

在你的邮件中,有拼写错误:

class ExampleMailer < ActionMailer::Base
  default from: "myemail@gmail.com"
  def sample_email(user)
    @user = user
    mail(to: @user.email, subject: 'sample email')
  end
end

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

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