Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gmail blocking rails app from sending email

I'm pretty sure I have everythign configured right, but I keep getting 'Net::SMTPAuthenticationError: 535-5.7.8 Username and Password not accepted. Learn more at' error when trying to send mails through my rails app. Also, there is only a blank space after the 'at' in the error message so I don't even know where to look for more information. I am also 100% sure the password and email are correct.

in my config/development.rb (I also have this in application.rb)

  config.action_mailer.delivery_method = :smtp
 # SMTP settings for gmail

config.action_mailer.smtp_settings = { 

 :address              => 'smtp.gmail.com',
 :port                 => 587,
 :domain               => 'gmail.com',
 :user_name            => '[email protected]',
 :password             => 'password',
 :authentication       => 'plain',
:enable_starttls_auto => true
}

I have allowed less secure apps access on the actual gmail account.

like image 762
xeroshogun Avatar asked May 19 '15 16:05

xeroshogun


People also ask

How do I use SMTP in Ruby on Rails?

Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.

What are Mailers in Rails?

1 Introduction. Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/views.


1 Answers

Google blocks all suspicious login attempts. By using app password, I was able to solve the problem:

  1. Enable 2-Step Verification if you haven't done so.
  2. Go to App passwords (Google will ask you to login again to verify here)
  3. Create a new App password: Choose Other (Custom name) under Select app, then enter app's name (any name you want)
  4. Click generate, a popup will be shown with a password. Use that password in your rails configuration instead of your google password.
like image 150
kcatstack Avatar answered Oct 09 '22 14:10

kcatstack