Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Production server doesn't recognise environment variables set by Figaro gem

I have my Sendgrid password set in an external file (config/application.yml) which I set up with the Figaro gem. This works fine on my local machine, but on my server I am getting an error that no password has been set:

ArgumentError (SMTP-AUTH requested but missing secret phrase)

When I change the Sendgrid config to just the plaintext password it works fine, so I assume that Rails isn't recognising the environment variable. The weird thing is that when I go into rails console production and execute puts ENV["SENDGRID_PASSWORD"] it works fine.

Any ideas?

Here's my Sendgrid config:

config.action_mailer.smtp_settings = {
  :address              => "smtp.sendgrid.net",
  :port                 => 587,
  :user_name            => "chrislawrence",
  :password             => ENV['SENDGRID_PASSWORD'],
  :domain               => "lakecinema.net.au",
  :authentication       => :plain,
  :enable_starttls_auto => true
}
like image 405
Chris Lawrence Avatar asked Oct 26 '12 03:10

Chris Lawrence


1 Answers

I had the same problem and couldn't figure out why Rails thought I wasn't giving it a password. Turns out I was defining config.action_mailer.smtp_settings in one file, and then adding key-value-combos to it in another file. The problem is that I was using merge instead of merge! so my password was never making it into smtp_settings but instead into a temporary hash.

From this experience I learnt that the error message you're getting is ActionMailer's way of saying "Where's the password?"

So my guess is that your issue is the inverse of Environment variable in Rails console and Pow, where an environment variable is working on the Rails server but not in Rails Console. Try executing:

$ echo "$SENDGRID_PASSWORD"

and see what you get. I have a feeling the Env variable is not set but that instead it's just a local variable in Rails Console.

like image 190
Isaac Betesh Avatar answered Sep 19 '22 11:09

Isaac Betesh