0

I have an app with registration using Devise gem and I have followed the Rails guide on Action Mailer Configuration for Gmail but when I click on Send me password reset instructions I don't receive any emails. This is what I have:

config/environments/development.rb

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

I have updated

config/initializers/devise.rb with:

config.mailer_sender = 'myemail@gmail.com'

I have also tried chaning authentication: "plain" to authentication: :plain, I have tried this tutorial, this, this and this, they all provide the same configuration but it doesn't work. I have allowed less secure apps here but no luck. I have also tried removing

domain: "example.com"

completely and changing

config.action_mailer.default_url_options = { host: 'localhost:3000' }

to

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

but that didn't help either. I've also tried:

ActionMailer::Base.smpt_settings = { ... }

instead but no luck.

I'v also tried putting this config to config/application.rb, restarting the server severl times but no luck.

This is the console log when send =ing password reset instructions:

Devise::Mailer#reset_password_instructions: processed outbound mail in 15.9ms
Sent mail to [hidden email] (269.2ms)
Date: Thu, 31 May 2018 22:40:03 +0200
From: [hidden email]
Reply-To: [hidden email]
To: [hidden email]
Message-ID: <5b105da3af6e6_164325fb584383ef@Home.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello [hidden email]!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><a href="http://localhost:3000/users/password/edit?reset_password_token=qeoAhLA2pevyy7wpbVEs">Change my password</a></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

Redirected to http://localhost:3000/users/sign_in
Completed 302 Found in 460ms (ActiveRecord: 9.9ms)

I have already tried everything. Any ideas?

I am using Rails 5.2

jedi
  • 2,003
  • 5
  • 28
  • 66
  • 1
    Just write plain username and password. Usually `ENV["TODO_USERNAME"],` is a fetch of Heroku or another hosting service environment variables. This does not apply to development. Alternatively writes username and password to `secrets.yml` and fetch with `Rails.application.secrets.TODO_USERNAME,`. Also try `authentication: :login` instead of `authentication: "plain"` – Maxence May 31 '18 at 23:31
  • Thanks, that worked – jedi May 31 '18 at 23:58
  • The problem might then be at Google. Connect to your Gmail account and check all security features. I remember having had to tick a box at Gmail settings before I switched to AWS SES. It's the same kind of security than when you connect from a new device to any of Google services... – Maxence Jun 01 '18 at 00:05
  • @Maxence do you know why ENV["USERNAME"] is not loading my variables? I can see the variables are defined in rails console properly. I've also tried another approach of havign a YAML file and store them there and the same thing - variables are read properly in rails console but not in config/environmnets/development.rb. Any idea why? – jedi Jun 01 '18 at 16:15
  • Where are located these variables locally ? I have never seen it working in development. to me the only way to get them locally is through the secrets.yml file but I am not expert in Rails... – Maxence Jun 01 '18 at 21:58
  • They are in my .bash_profile. I've finally managed to get this to work. I've moved to Sendgrid. They also say to put the config into `config/environment.rb`. – jedi Jun 02 '18 at 09:02

0 Answers0