I have tried to execute the following program in Python for sending an email. The program is as follows:
Python Code
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from pathlib import Path
import smtplib
message = MIMEMultipart()
message["from"] = "Sarmad Alsaadi"
message["to"] = "testpythonmail54@gmail.com"
message["subject"] = "This is a test"
message.attach(MIMEText("Body", "plain"))
with smtplib.SMTP(host="smtp.gmail.com", port=587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login("testpythonmail54@gmail.com", "acrobat12345")
smtp.send_message(message)
print("Sent........")`
But I am getting the following error
File “e:\Tutorials\Mosh\mastery_course\sending_emails.py”, line 16, in
smtp.login(“testpythonmail54@gmail.com”, “acrobat12345”)
File “C:\Program Files\Python311\Lib\smtplib.py”, line 750, in login
raise last_exception
File “C:\Program Files\Python311\Lib\smtplib.py”, line 739, in login
(code, resp) = self.auth(
^^^^^^^^^^
File “C:\Program Files\Python311\Lib\smtplib.py”, line 662, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b’5.7.8 Username and Password not accepted. Learn more at\n5.7.8 Check Gmail through other email platforms - Gmail Help s7-20020adfeb07000000b002bff1de8d4bsm11043112wrn.49 - gsmtp’)`
I am using VS code with Python extension installed on it. Anything else written in Python get executed successfully and I faced no problems with other programs being executed via the Terminal.
I would so much appreciate it if someone could kindly extend me a helping hand
I found some similar previous topics as mine but they were different in errors produces