Friday, 17 May 2019

python - Login credentials not working with Gmail SMTP

I am attempting to send an email in Python, through Gmail. Here is my code:



import smtplib


fromaddr = '......................'

toaddrs = '......................'
msg = 'Spam email Test'

username = '.......'
password = '.......'

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

server.sendmail(fromaddr, toaddrs, msg)
server.quit()


I get the error:



Traceback (most recent call last):
File "email_send.py", line 18, in
server.login(username, password)
File "C:\.....\Python\lib\smtplib.py", line 633

, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepte
d. Learn more at\n5.7.8 http://support.google.com/mail/bin/answer.py?answer=1425
7\n5.7.8 {BADCREDENTIALS} s10sm9426107qam.7 - gsmtp')


This seems to be a problem with the login. I am certain that my login details are correct, except for one thing. Should username be "blah@gmail.com", or simply "blah"? I tried both, same error.



Any idea whats wrong?




NOTE: all the periods are instead of password/email/file paths/etc.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...