2

I am using devise for authentication. It provides a forgot password link. When i send email then the email is not sent. Following is the settings i have used. Can you tell me why gmail is not sending the email? I have also turned on "allow less secure app to send email" and i have also enabled imap in gmail setting.

application.rb has the following setting.

ActionMailer::Base.smtp_settings = {


  :address => 'smtp.gmail.com',
  :domain => 'mail.google.com',
  :port => 587,
  :user_name => '[email protected]',
  :password => 'validpassword',
  :authentication => 'login',
  :enable_starttls_auto => true


}

development.rb has

  config.action_mailer.default_url_options = { host: '127.0.0.1'}


  config.action_mailer.delivery_method = :smtp

After sending the email i get the following text in the console.

Devise::Mailer#reset_password_instructions: processed outbound mail in 215.2ms
Sent mail to [email protected] (1097.6ms)
Date: Thu, 29 Dec 2016 09:50:41 +0000
From: [email protected]
Reply-To: [email protected]
To: [email protected]
Message-ID: <5864dc7161acb_173921a07788707d@kofhearts-rubyonrails-3267120.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

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

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

<p><a href="http://127.0.0.1/users/password/edit?reset_password_token=WQxYad91mPghMxaurYA5">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 https://rubyonrails-kofhearts.c9users.io/users/sign_in
Completed 302 Found in 1965ms (ActiveRecord: 14.7ms)

UPDATE:

I am just following this tutorial.

https://www.youtube.com/watch?v=ZEk0Jp2dThc

Send email is not working with the settings that are specified in this video.

2
  • May be duplicate stackoverflow.com/questions/25735206/… Commented Dec 29, 2016 at 9:56
  • I know this isn't an answer to your question, but I gave up on using smtp through gmail. I now use sendinblue, they have an smpt service which is free for about 300 emails a day. Also a nice ruby gem so it's quite easy to use.
    – Eyeslandic
    Commented Dec 29, 2016 at 10:07

4 Answers 4

4

Enabling less secure apps in my account settings worked for me.

Google Account settings > Signing in to Google > scroll down to the bottom

Turn on allow less secure apps. Try sending the email again.

0

That's should work. Maybe you could also turn on config.action_mailer.raise_delivery_errors = true in config/environments/development.rb. It's easier to debug.

Maybe you forget to set config.action_mailer.perform_deliveries = true in config/environments/development.rb?

1
  • thanks but even after adding the perform_deliveries setting and raise_delivery_errors flag the email is not sending. I have updated my post above with the console message that is printed after i click on "send me reset password instructions" that is supposed to send email to the provided email.
    – kofhearts
    Commented Dec 29, 2016 at 9:54
0

Have you tried this?

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {  
  :address              => "smtp.gmail.com",  
  :port                 => 587,  
  :domain               => "gmail.com",  
  :user_name            => "[email protected]",  
  :password             => "secret",  
  :authentication       => "plain"
  # :enable_starttls_auto => true # I don't have this, but it should work anyway 
} 

it it's sent maybe you don't receive it because of the spam filter, first thing to check:

class UserMailer < ActionMailer::Base
  default :from => "[email protected]"
  # ...
end

You also check your Forwarding and POP/IMAP in your gmail..

include these line of codes on your development.rb

config.action_mailer.default_url_options = {host: 'your server' } # ex. localhost:3000
config.action_mailer.raise_delivery_errors = true # to raise error if smtp has error on setup
config.action_mailer.default :charset => "utf-8"
4
  • thanks i added from and that also didnt work. i also checked the spam and the message is not there.
    – kofhearts
    Commented Dec 29, 2016 at 10:01
  • @user734861 ok fine.. now you must enable you "Forwarding and POP/IMAP".. Commented Dec 29, 2016 at 10:10
  • i have enabled imap. should i also enable pop?
    – kofhearts
    Commented Dec 29, 2016 at 10:11
  • Let us continue this discussion in chat.
    – kofhearts
    Commented Dec 29, 2016 at 10:17
0
  1. If you are working with Gmail you should activate permission to externals apps send email through SMTP.
  2. In development mode Rails does not send emails, you should run Rails in production rails s -e production or turn on config.action_mailer.raise_delivery_errors = true
  3. do not forget to use mail().deliver or for Rails 5+ mail().delivery_now

look you this is my SMTP configuration

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => ENV['mailer_address'],
    :port                 => ENV['mailer_port'],
    :user_name            => ENV['mailer_username'],
    :password             => ENV['mailer_password'],
    :authentication       => "plain",
    :enable_starttls_auto => true
  }

this is my Class Mailer

def send_email
 mail(to: "[email protected]", subject: 'not reply this message').deliver
end

I call that function from my controller. If you got any error you should print it to check what is the problem.

begin
  myMailer.send_email
rescue  Exception => e
  flash[:error] = "Imposible sent email, #{e.inspect}"
end
2
  • thanks jeff but i have enabled pop, imap and also enabled less secure apps to access gmail permission. Still with the above settings the email is not getting delivered.
    – kofhearts
    Commented Dec 29, 2016 at 10:17
  • can you create a mailer testing if it is working?, which Rails version are you working?
    – Jeff
    Commented Dec 29, 2016 at 12:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.