Чтобы воспроизвести мою проблему, вот мой код:
import smtplib
from email.message import EmailMessage
email=EmailMessage()
email['from']='Pratik Mishra'
email['to']='pratikmishra79@gmail.com'
email['subject']='Hi there! congratulations you won $10,000'
email.set_content("i am a python master ")
with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login('pratik.jgd17@gmail.com','password')# can't write password here
smtp.send_message(email)
print("hello this was a joke")
Я получаю это выходное сообщение из командной строки:
C:\Users\prati\Documents>python email_sender.py
Traceback (most recent call last):
File "email_sender.py", line 11, in <module>
smtp.login('pratik.jgd17@gmail.com','password')
File "C:\Users\prati\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 734, in login
raise last_exception
File "C:\Users\prati\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 723, in login
(code, resp) = self.auth(
File "C:\Users\prati\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 646, 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 a23sm994647pfo.145 - gsmtp')