Net :: SMTPAuthenticationError(不接受535-5.7.8用户名和密码。)仅限Openshift生产

时间:2016-03-18 22:42:31

标签: ruby-on-rails openshift actionmailer

我试图通过gmail / actionmailer发送电子邮件,它在我的本地开发框中运行完美,但是当我尝试在生产服务器上运行相同的代码时,它会给我一个Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted.。我认为这是因为gmail拒绝了我未知服务器的登录凭据。但我不确定!我该如何解决?

背景:

我正在使用figaro gem,我在openshift服务器上设置我的环境变量:rhc set-env。我检查过服务器上是否设置了环境变量。

问题hereherehere都很好,但没有做任何事来解决我的问题。我的问题有点不同,因为它只显示在我的服务器上,一切正常在我的本地方框上。

开发:

在开发模式下,我安装了figaro gem,并且我的配置文件存储在application.yml中,检入git。 这是它的内容:

## config/application.yml
# Add configuration values here, as shown below.

gmail_username: 'PLACE_HOLDER_EMAIL@gmail.com'
gmail_password: 'PLACE_HOLDER_PASSWORD'

在我的控制器中:

## PLACEHOLDER_controller.rb
 def create
    @placeholder = Placeholder.new(placeholder_params)

    respond_to do |format|
      if @placeholder.save

        puts "SENDING!!!!"
        puts "Sending to: #{ENV['gmail_username']}..."
        PLACEHOLDERMailer.placeholder_email(some, params).deliver         
        puts "SENT!!!  IN THEORY!"
    end
  end

生产:

   ## /config/environments/production.rb
  # SMTP                                                                                                                                                                                                           
  config.action_mailer.delivery_method = :smtp
  # SMTP settings for gmail                                                                                                                                                                                        
  config.action_mailer.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :user_name            => "#{ENV['gmail_username']}",
    :password             => "#{ENV['gmail_password']}",
    :authentication       => "plain",
    :enable_starttls_auto => true
  }

生产:

我用git将代码推送到我的OpenShift仓库,服务器重新启动,表面上一切都很好。除了当我创建一个新的占位符时,我从服务器获得500回。

这是日志输出:

>> rhc tail -a MY_APP
 SENDING!!!!
Sending to: "PLACE_HOLDER_EMAIL@gmail.com"... ## This is the correct email! It's clearly pulling the proper values from ENV.
INFO -- :   Rendered placeholder_mailer/placeholder_email.text.erb (0.1ms)
INFO -- : 
Sent mail to 9739069711@txt.att.net (132.3ms)
INFO -- : Completed 500 Internal Server Error in 224ms
FATAL -- : 
Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted. Learn more at
 ):
 app/controllers/placeholders_controller.rb:35:in `block in create'
app/controllers/placeholders_controller.rb:29:in `create'

其中表示不接受用户名和密码。现在,我知道我有正确的用户名和密码。我相当肯定不是问题。我怀疑(如链接问题中所述)smtp.gmail.com拒绝我从未知服务器登录。

在有人建议之前,我已经:

TL; DR

我试图从服务器发送电子邮件。当我在服务器上运行它时,它会给我:Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted.。我认为这是因为gmail拒绝来自未知服务器的登录凭据。我该如何解决?

1 个答案:

答案 0 :(得分:0)

如果您尝试以编程方式每十分钟访问一次,那么gmail blocks you temporarily就会出现DwinsHs。我想我在测试功能时必须这样做。

相关问题