Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 action mailer SMTP-AUTH error missing secret phrase?

I'm having trouble sending email using Rails 4 action mailer via gmail. It all should be so simple ... yet it isn't working. Specifically, I get

ArgumentError (SMTP-AUTH requested but missing secret phrase):

I've read the other questions here regarding the situation, but most of them had simple fixes ("user_name" instead of "username", or ENV variable was wrong). I've double checked, and I'm certain my credentials are correct. Here is the relevant section of my development.rb:

config.action_mailer.delivery_method = :smtp                          
config.action_mailer.smtp_settings = {                    
  address: 'smtp.gmail.com',                                      
  port: 587,  
  domain:  'mydomain.com', 
  user_name:  ENV["GMAIL_USERNAME"],  
  password:  ENV["GMAIL_PXXWRD"],   
  authentication: 'plain',
  enable_starttls_auto: true                         
}  

I initially had the credentials in plaintext, but that I though maybe I should move them to env variables to solve the issue. It didn't change anything. As a note, my gmail is a company gmail, so it doesn't actually end in "@gmail.com". I'm not sure if that changes anything, but I thought I'd mention it. I've also tried with a standard gmail address, it changes nothing.

Also, does "missing secret phrase" refer to a bad password? Or is it not finding a password to begin with? What else could cause the error? Thanks for your time guys.

like image 626
minifigmaster125 Avatar asked Oct 20 '25 01:10

minifigmaster125


1 Answers

I just dealt with a very similar scenario in an app I'm working on. I was getting the exact same "SMTP-AUTH requested but missing secret phrase" error. What ultimately fixed it for me was two-fold:

1) Make sure that you're using an application-specific password for gmail. Instructions from Google here > How to generate an App password. Note that if you don't already have 2-factor authentication, you'll need to set that up first as well. You'll end up with an application password that is 16 characters long. You'll use that as the password that Rails uses via your SMPT settings.

2) Make sure that you have appropriately setup your local environment variables file so that it loads upon compiling of the Rails app, and is excluded from git tracking by putting the filename in your gitignore. I use a file called app_name/config/local_env.yml, but you could also use the standard secrets.yml file that comes with Rails 4.2, or the figaro gem is pretty popular for managing ENV variables. This RailsApps page gives a good overview of how to manage your ENV variables.

Ultimately, my SMTP settings ended up looking nearly identical to yours:

#GMAIL CONFIG
config.action_mailer.default_url_options = { :host =>'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}

Best of luck!

like image 138
bbrails09 Avatar answered Oct 21 '25 18:10

bbrails09



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!