【问题标题】:Rails Environment Variable Not Getting Set on Production on HerokuRails 环境变量未在 Heroku 上的生产环境中设置
【发布时间】:2017-08-31 08:23:24
【问题描述】:

我正在尝试在 Heroku 上使用 Mailgun 和 DelayedJob 设置 ActionMail,并且我已经完成了一切工作,DelayedJob 正在使用 Mailgun 发起请求,但我从 Mailgun 收到了 400 Bad Request: 'from' parameter is missing

我的邮件是app/mailers/example_mailer.rb:

class ExampleMailer < ApplicationMailer

def sample_email(user)
    @user = user
    mailgun_client = Mailgun::Client.new ENV['MAILGUN_API_KEY']
    message_params = {:from     => ENV['GMAIL_USERNAME'],
                      :to       => @user.email,
                      :subject  => 'Sample Mail Using Mailgun API',
                      :text     => 'Testing...'}

    mailgun_client.send_message ENV['MAILGUN_DOMAIN'], message_params

  end
end

我的config/application.yml

MAILGUN_API_KEY:  '[REDACTED]'
MAILGUN_ADDRESS:  'smtp.mailgun.org'
MAILGUN_PORT:     587
MAILGUN_DOMAIN:   '[REDACTED]'
MAILGUN_USERNAME: '[REDACTED]'
MAILGUN_PASSWORD: '[REDACTED]'
GMAIL_USERNAME:   '[REDACTED]'

因此,由于错误是未正确设置 from 字段,因此我登录了我的 heroku 控制台并测试了我的 ENV 变量,你瞧,除了 ENV['GMAIL_USERNAME'] 之外,所有这些变量都存在。我的生产环境中是否会缺少此变量?我不确定如何调试它,因为我以前从未遇到过这样的环境变量问题。

【问题讨论】:

    标签: ruby-on-rails ruby heroku delayed-job mailgun


    【解决方案1】:

    我是个白痴,我设置了 figaro 来处理我的环境变量并忘记将它们发布到 heroku:

    figaro heroku:set -e production
    

    此外,您需要将 application.yml 中的所有变量包装在字符串中,因此我还必须将 MAILGUN_PORT 更新为“587”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 2017-12-17
      • 2021-07-30
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 2020-01-01
      相关资源
      最近更新 更多