Rails:Net :: SMTPAuthenticationError(535身份验证失败:用户名/密码错误) [英] Rails : Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password )

查看:292
本文介绍了Rails:Net :: SMTPAuthenticationError(535身份验证失败:用户名/密码错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to setup email in my rails application and i'm getting the error "Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password )" when i trigger the mail action in production environment.

controller:

controller:

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

config / environments / production.rb:

config/environments/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:

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


推荐答案

邮件中有错字:

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 。没关系。

And in your production.rb, you can write username as myemail. That's fine.

让我知道它是否无效。

Let me know if its not work..

这篇关于Rails:Net :: SMTPAuthenticationError(535身份验证失败:用户名/密码错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆