1

I would like to send an email from a python script. However, when I try run server.login I receive the following error: smtplib.SMTPAuthenticationError: (535, '5.7.0 (#MBR1212) Incorrect username or password.')

I have tried this both with Gmail and Yahoo accounts. The Gmail error is:

smtplib.SMTPAuthenticationError: (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 u2sm21203448pbs.42 \
- gsmtp')

The Yahoo error is

smtplib.SMTPAuthenticationError: (535, '5.7.0 (#MBR1212) Incorrect username or password.')

The code I am using is the following. Username and password are string variables that represent my correct username and password.

server = smtplib.SMTP('smtp.mail.yahoo.com', 587)
server.ehlo()
server.starttls()
server.login(username, password)

I am using Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, May 27 2014, 14:58:54)

bjoseph
  • 2,116
  • 17
  • 24
  • Are you _sure_ the username and password are correct? Note that some accounts will require you to send a full address, like `bjoseph@yahoo.com`, not `bjoseph`. (With Yahoo, IIRC, the domain is optional if it's `yahoo.com`, but don't quote me on that; test it or search for docs.) – abarnert Jul 29 '14 at 20:49
  • hi, yes i am sure. i have tried both permutations of the email addresses `'blah@gmail.com'` and `'blah'`. still no dice – bjoseph Jul 29 '14 at 20:52
  • OK, hopefully this won't seem stupid and condescending, but I make these kinds of mistakes all the time… Your sample code shows logging into Yahoo's mailserver, but your comment says you tried your gmail email address, so… any chance you've mixed them up and sent your gmail credentials to Yahoo? – abarnert Jul 29 '14 at 21:35
  • One more thing to rule out: I don't know about Yahoo, but Gmail can lock out your account if it thinks you're trying to spam from it or someone is trying to hack it. Until you go to the website and login manually (logging out first, if necessary) and answer the Captcha, it will give you bad-username errors. – abarnert Jul 29 '14 at 21:37
  • no worries, you don't sound condescending at all! I make these mistakes often too. I've also tried with Gmail's mailserver. – bjoseph Jul 29 '14 at 21:40
  • Well, I just tested your code with my accounts (using the full email) (and using `smtp.gmail.com` for the Gmail one). Yahoo worked; Gmail gave me a 535 error with a slightly different string, which was fixed by me doing the Captcha thing on the website, and now it works too. Can you try creating a throwaway Yahoo account and testing with that to see if it's something weird about your accounts? – abarnert Jul 29 '14 at 21:56
  • its probably similar problem as this one, but yahoo instead of gmail: http://stackoverflow.com/questions/16512592/login-credentials-not-working-with-gmail-smtp – radtek Dec 16 '14 at 23:38

1 Answers1

6

You should go to yahoo email account and then go to Account security and active Allow apps that use less secure sign in for solve your problem.

Saeed Ghareh Daghi
  • 1,164
  • 1
  • 13
  • 21