【问题标题】:Ruby on Rails 4 with SendGrid - authentication fails , but only on production server on Linode带有 SendGrid 的 Ruby on Rails 4 - 身份验证失败,但仅在 Linode 上的生产服务器上失败
【发布时间】:2014-11-16 18:16:13
【问题描述】:

在我的应用程序中,我设置了 sendgrid SMTP 服务。我正在使用 Figaro gem 为 SMTP 配置设置 ENV 变量。

在开发模式下一切正常 - 我可以发送电子邮件。但是当我在 Linode 上部署到我的 VPS 时,每次我尝试发送邮件时都会得到:

Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password

在生产服务器的 Rails 控制台上,我可以验证 ENV["GRID_USER']ENV["GRID_PASS"] 是否正确。当我检查Figaro.env.grid_userFigaro.env.grid_pass(在生产模式下)时,我得到的结果相同。 凭据正确。

身份验证失败的原因可能是什么,令人惊讶的是仅在生产模式下?

在这里你可以在production.rb 中看到我的 smtp 配置:

config.action_mailer.smtp_settings = {
    address: "smtp.sendgrid.net",
    user_name: ENV['GRID_USER'],
    password: ['GRID_PASS'],
    domain: "why.bio",
    port: 587,
    authentication: 'plain',
    enable_starttls_auto: true
    }

这是我在application.yml 中声明我的凭据的方式:

GRID_USER: "MySendGridUserName"
GRID_PASS: "very_wierd_password"

我在 StackOverflow 和许多博客中检查了数百个问题,但找不到解决方案。

【问题讨论】:

    标签: ruby-on-rails email ruby-on-rails-4 sendgrid


    【解决方案1】:

    您需要在配置中使用ENV['GRID_PASS'] 而不仅仅是['GRID_PASS']

    【讨论】:

    • 谢谢你,布莱斯。我花了整个周末。我希望我有你准确的眼睛。
    • 哈哈,不用担心!我之前也在语法错误上浪费了更长的时间!祝您其余的编码工作好运!
    • 你确实拯救了我的一天。开心点,布莱斯。
    猜你喜欢
    • 1970-01-01
    • 2015-03-01
    • 2017-05-24
    • 2020-05-26
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多