python - Login credentials not working with Gmail SMTP -
i attempting send email in python, through gmail. here 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 error:
traceback (most recent call last): file "email_send.py", line 18, in <module> 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 , 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 problem login. login details correct, except 1 thing. should username "blah@gmail.com", or "blah"? tried both, same error.
any idea whats wrong?
note: periods instead of password/email/file paths/etc.
i ran similar problem , stumbled on question. got smtp authentication error user name / pass correct. here fixed it. read this:
https://support.google.com/accounts/answer/6010255
in nutshell, google not allowing log in via smtplib because has flagged sort of login "less secure", have go link while you're logged in google account, , allow access:
https://www.google.com/settings/security/lesssecureapps
once set (see screenshot below), should work.
login works:
smtpserver = smtplib.smtp("smtp.gmail.com", 587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo() smtpserver.login('me@gmail.com', 'me_pass')
response after change:
(235, '2.7.0 accepted')
response prior:
smtplib.smtpauthenticationerror: (535, '5.7.8 username , password not accepted. learn more at\n5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 g66sm2224117qgf.37 - gsmtp')
update: see answer here: how send email gmail provider using python?
Comments
Post a Comment