RQ Bukhari
RQ Bukhari

Reputation: 167

Ruby on rails email error 535-5.7.1 Username and Password not accepted

I am getting error when I try to send an e-mail. I am trying to send email from localhost.. the actionmailer setting are

ActionMailer::Base.smtp_settings = {

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

When I configured it first time the email was working fine. but after sending 4 or 5 email the functionality stopped working and shows me this error

Net::SMTPAuthenticationError ............

535-5.7.1 Username and Password not accepted.

Where could be a problem?

Thanks..

Upvotes: 6

Views: 6605

Answers (4)

user5287360
user5287360

Reputation:

Goto config/initializers/setup_mail.rb Check whether the configuration there matches the configuration written in the development.rb file.It should look like the following in both files:

config.action_mailer.smtp_settings = {
     :address =>"[email protected]",
     :port => 587,
     :domain => "gmail.com",
     :user_name => "[email protected]",
     :password => "**********",
     :authentication => 'plain',
     :enable_starttls_auto => true,
     :openssl_verify_mode => 'none' 
     }  

This will most certainly solve your problem.

Upvotes: 0

bluswtr
bluswtr

Reputation: 1

If you're sure you've checked your settings many times and still get:

535-5.7.8 Username and Password not accepted

Try restarting your rails server especially when you've changed your yaml file or environment files.

rails s

See When do I need to restart server in Rails? for more information on when and why you should restart.

Upvotes: 0

Jonah
Jonah

Reputation: 16202

I was trying to send using smtp from a ruby application on my hosted webserver, and was getting denied, something Gmail does a security precaution.

The solution was first to login to gmail in my own browser on my laptop, as usual. There was an alert at the top saying gmail had detected suspicious activity. "Was it you?" I clicked through a few steps saying it was me and was brought to a screen that said:

Next step

Sign in using the application you want to authorize access to your account within the next ten minutes. Google will remember the application after it signs in, and will allow it to access your account in the future as long as it uses the correct password.

I then ssh'd into my server, and from the command line did:

lynx http://mail.google.com/mail/?ui=html

I then logged into gmail using lynx, and the problem was solved.

Upvotes: 2

djp3
djp3

Reputation: 166

I had the same problem and when I double-checked the password I realized that I had typed it in wrong.

So, the error can be generated by a bad password and presumably a bad username as well. After you correct the username and password make sure you restart your rails application.

I also presume that you aren't actually using the literal text "mydomain.com", right?

Upvotes: 0

Related Questions