简体   繁体   English

在Heroku上未设置Rails环境变量

[英]Rails Environment Variable Not Getting Set on Production on Heroku

I am trying to setup ActionMail using Mailgun and DelayedJob on Heroku and I've got everything working to the point where DelayedJob is initiating the request with Mailgun, but I'm getting a 400 Bad Request: 'from' parameter is missing from Mailgun. 我正在尝试在Heroku上使用Mailgun和DelayedJob设置ActionMail,并且一切正常,DelayedJob正在使用Mailgun发起请求,但是我收到了400 Bad Request: 'from' parameter is missing Mailgun中400 Bad Request: 'from' parameter is missing

My mailer is app/mailers/example_mailer.rb : 我的邮件是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

My config/application.yml : 我的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]'

So since the error is that the from field isn't being set properly I logged into my heroku console and tested my ENV variables and lo and behold all of them are present except ENV['GMAIL_USERNAME'] . 因此,由于错误是无法正确设置from字段,因此我登录了heroku控制台并测试了我的ENV变量,并且lo看到除了ENV['GMAIL_USERNAME']之外所有变量都存在。 Is there any reason why this variable would be missing in my production environment? 有什么理由导致我的生产环境中缺少此变量? I'm not sure how to debug this as I've never come across a problem with environment variables like this before. 我不确定如何调试它,因为我以前从未遇到过这样的环境变量问题。

I'm an idiot, I setup figaro to handle my environment variables and forgot to publish them to heroku: 我是个白痴,我设置了figaro来处理我的环境变量,却忘了将它们发布到heroku:

figaro heroku:set -e production

Also, you need to wrap all variables in application.yml in strings, so I also had to update the MAILGUN_PORT to '587'. 另外,您需要将application.yml中的所有变量包装在字符串中,因此我还必须将MAILGUN_PORT更新为'587'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Heroku上的生产环境的Rails应用程序中设置邮件程序 - How to set up mailer in Rails app for production environment on Heroku Rails / Heroku中的生产环境如何工作? - How does the production environment in Rails / Heroku work? Rails 4-.js文件不在生产环境中运行-Heroku - Rails 4 - .js files not running in production environment - Heroku 无法在Heroku上运行的Ruby on Rails 4.1.4应用程序中为生产环境设置secret_key_base - Unable to set secret_key_base for the production environment in Ruby on Rails 4.1.4 application running on Heroku 设置系统目录Rails生产环境 - Set System Directory Rails Production Environment 在Heroku中获取ActionViewTemplate错误,但不在本地Rails环境中 - Getting ActionViewTemplate error in Heroku but not local rails environment Rails 4 - 如何优化Heroku生产环境? - Rails 4 - How do I optimize my Heroku production environment? ruby on rails:heroku:“生产”环境缺少“secret_key_base” - ruby on rails: heroku: Missing `secret_key_base` for 'production' environment Heroku始终运行资产:使用Rails 3.2的生产环境进行预编译 - Heroku always runs assets:precompile with the production environment for Rails 3.2 使用 Heroku 登台环境(使用生产设置)的 Rails 加密凭证 - Rails encrypted credentials with Heroku staging environment (using production setting)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM