[英]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.