Mail notifications to self Net::SMTPAuthenticationError

I am trying to set up a mailer to send myself notification methods. I am
currently trying to get the mailer to send myself a simple message when
I
go to the URL localhost:3000/send_mail

I am currently getting this error:

Net::SMTPAuthenticationError in HomeController#send_mail
534-5.7.9 Application-specific password required

development.rb:

  config.action_mailer.raise_delivery_errors = true
  host = 'localhost:3000'
  config.action_mailer.default_url_options = { host: host }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            '[email protected]',
    password:             'mypwd',
    authentication:       'plain',
    enable_starttls_auto: true  }

routes:

match ‘/send_mail’, to: “home#send_mail”, via: “get”

home controller:

class HomeController < ApplicationController
  def index
  end

  def send_mail
  ActionMailer::Base.mail(:from => "[email protected]", :to =>

[email protected]”, :subject => “Contact request”, :body =>
“test”).deliver_now
render nothing: true
end
end

Hello,

The reason you are getting that error is because more than likely you
have
set up 2 factor authentication with Google/Gmail. So it is saying you
need
to include a application specific password. In other words don’t use
the
usual login password, create an application specific password on
Google/Gmail and then use that in your smtp settings. Hope this helps.

Mike R.

Take a look at:

-Rob

Thank you!! worked like a charm!

thank you!!! worked perfectly!!

It is because Google blocks gmail smtp sign-in attempts from apps which do not use modern security standards (mentioned on their support page). You can however, turn on/off this safety feature by going to the link below:

Go to this link and select Turn On
https://www.google.com/settings/security/lesssecureapps

Moreover google block an ip when you try to send a email since a unusual location, so, you can unblock in the next link

and clicked in

accounts.google.com/DisplayUnlockCaptcha .