[Tutor] Full code i get error when i send email using python
Michael Crooks
mikeycrooks17 at gmail.com
Sat May 9 04:31:16 EDT 2020
import smtplib
host = "smtp.gmail.com"
port = 587
username ="testingprogramsmichael at gmail.com"
password = "Oliver17"
from_email = username
to_list = ["testingprogramsmichael at gmail.com"]
email_conn = smtplib.SMTP(host, port)
email_conn.ehlo()
email_conn.starttls()
email_conn.login(username, password)
email_conn.sendmail(from_email, to_list, "hello there this is an email
message")
email_conn.quit()
This is what i get when i run it in terminal ( i think google is blocking
me because im running this from pi 4 using terminal)
>>> import smtplib
>>>
>>> host = "smtp.gmail.com"
>>> port = 587
>>> username ="testingprogramsmichael at gmail.com"
>>> password = "Oliver17"
>>> from_email = username
>>> to_list = ["testingprogramsmichael at gmail.com"]
>>>
>>> email_conn = smtplib.SMTP(host, port)
>>> email_conn.ehlo()
(250, b'smtp.gmail.com at your service, [63.143.118.227]\nSIZE
35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES\nPIPELINING\nCHUNKING\nSMTPUTF8')
>>> email_conn.starttls()
(220, b'2.0.0 Ready to start TLS')
>>> email_conn.login(username, password)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/smtplib.py", line 730, in login
raise last_exception
File "/usr/lib/python3.7/smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "/usr/lib/python3.7/smtplib.py", line 642, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not
accepted. Learn more at\n5.7.8
https://support.google.com/mail/?p=BadCredentials 64sm3599843vkx.12 -
gsmtp')
>>> email_conn.sendmail(from_email, to_list, "hello there this is an email
message")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/smtplib.py", line 867, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required. Learn
more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError
64sm3599843vkx.12 - gsmtp', 'testingprogramsmichael at gmail.com')
More information about the Tutor
mailing list