6

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 => "do-not-reply@mydomain.com",
 
  :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..

Community
  • 1
  • 1
RQ Bukhari
  • 167
  • 3
  • 8

4 Answers4

2

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.

Community
  • 1
  • 1
Jonah
  • 15,806
  • 22
  • 87
  • 161
  • Well you are rite but the issue was something different with my application. If I'm providing the login information then I think I don't need to do that.And for my rails application google even don't ask for the application authorization. Well The issue is fixed now may be that was a temporary problem but later it was working for me with these same configurations. – RQ Bukhari Feb 21 '13 at 06:23
  • Yes you may have been experiencing something different, but fwiw I was sending my login credentials, and they were correct. Google just didn't like the IP address of my web host for security reasons and hence I had to do go through the process described above. Glad your problem is fixed though. – Jonah Feb 21 '13 at 06:48
0

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.

Community
  • 1
  • 1
bluswtr
  • 1
  • 3
0

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 =>"smtp.gmabirdvision17@gmail.comil.com",
     :port => 587,
     :domain => "gmail.com",
     :user_name => "mygmail@gmail.com",
     :password => "**********",
     :authentication => 'plain',
     :enable_starttls_auto => true,
     :openssl_verify_mode => 'none' 
     }  

This will most certainly solve your problem.

0

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?

djp3
  • 166
  • 1
  • 8
  • No am not using the text "mydomain.com" I am using the proper domain name. The username and password is also correct. I changed the username and password and used a gmail account and then the email function worked. But When I use the username and password of mydomain then the email functionality fails. – RQ Bukhari Apr 02 '12 at 06:25
  • is smtp running on your domain? – djp3 Apr 04 '12 at 00:21
  • Yes, SMTP is running on the domain. The problem is solved now. Thanks :) – RQ Bukhari Aug 23 '12 at 12:47
  • I'm upvoting this because I did this. I feel really stupid. I ended it in "1234" but it actually ended in "123". I know this is the *obvious* answer, but the obvious answer is normally the one that is causing the problem. Thanks for this! – Kenton de Jong Oct 23 '14 at 15:27