Reputation: 2705
I'm struggling to set figaro up on my rails 4 app.
I have application.yml:
GMAIL_USERNAME_CFR: [email protected]
GMAIL_PW_PROD_CFR: bbb
GMAIL_USERNAME_PROD_WELCOME: [email protected]
GMAIL_PW_PROD_WELCOME: ddd
I have a production.rb file:
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: Figaro.env.GMAIL_USERNAME_CFR,
password: Figaro.env.GMAIL_PW_PROD_CFR,
authentication: 'plain',
enable_starttls_auto: true }
In my user.rb I have 2 mailers set up. When I don't use figaro and just put the username and password directly in the production.rb file - these mailers work. Using Figaro, I get an authentication error.
My user.rb methods are:
def send_admin_mail
puts "the value is:" + Figaro.env.GMAIL_USERNAME_CFR.to_s
AdminMailer.new_user_waiting_for_approval(self).deliver
end
def send_user_welcome_mail
AdminMailer.new_user_waiting_for_access(self).deliver
end
You can see that I tried to figure out the problem with the puts line in the first method above. The log puts 'the value is' and then does not put the username as a string.
My mailers are:
def new_user_waiting_for_approval(user)
@user = user
mail(to: "[email protected]", from: Figaro.env.GMAIL_USERNAME_CFR,
subject: "Registration Request #{user.first_name} #{user.last_name} <#{user.email}>")
end
def new_user_waiting_for_access(user)
@user = user
mail(to: user.email, from: "[email protected]", subject: "Welcome, #{user.first_name}")
end
You can see above that I have tried to use figaro in the first mailer and the email address in the second email. Neither option works. I have also tried ENV[] instead of Figaro.env before the username and password.
My console shows the details correctly when I convert them to strings - except they are shown between "". I assume that's of no significance.
Can anyone see what I need to do to fix my figaro setup?
Thank you
Upvotes: 1
Views: 1510
Reputation: 2705
Ok, my problem was I didn't load my environment variables from my application.yml
to Heroku. Because the file is listed in .gitignore
, it won't be commited to GitHub.
To load the environment variables to Heroku, do figaro heroku:set -e production
. As it's explained here.
Upvotes: 2
Reputation: 1421
You don't need to call Figaro.env
for it to read your application.yml file. Just grab the environment variables using standard rails.
For example, change:
Figaro.env.GMAIL_USERNAME_CFR
To:
ENV['GMAIL_USERNAME_CFR']
Change all instances of Figaro.env
to this format.
Also, make the variables in your application.yml file set to strings.
GMAIL_USERNAME_CFR: "[email protected]"
GMAIL_PW_PROD_CFR: "bbb"
GMAIL_USERNAME_PROD_WELCOME: "[email protected]"
GMAIL_PW_PROD_WELCOME: "ddd"
Upvotes: 0