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.

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!


for me i had put the password in bashrc file and i forgot to restart the puma server. if you restart the puma server then this error is fixed.


Need Your Help

Collision Detection Errors and Lagging movement

c# xna-4.0 game-physics

this is my first time doing this and im sorry if im doing this wrong but for the last couple of weeks i've been working on a little project with xna and c# while following a book

C++ linking error with multiple .cpp files

c++ header visual-studio-2013

This is my header file. It complies just fine if I only include it in one .cpp file, but as soon as I try to include it in two or more .cpp files it creates an error as long as the maps are include...