I am using this following code however I keep getting an error.. what am I doing wrong.,
import os
import smtplib
sender_email = "myemail@gmail.com"
rec_email = "myemail@gmail.com"
username = "myemail@gmail.com"
password = input(str("EnterPassword"))
message = "Hey, this was sent using python"
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
print("connected")
server.login(username,password)
print("Login success")
server.sendmail(sender_email,rec_email,message)
print("Email has been sent")
Error:
connected
Traceback (most recent call last):
File "C:/Users/<user>/PycharmProjects/Report/main.py", line 12, in <module>
server.login(username,password)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\smtplib.py", line 730, in login
raise last_exception
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\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 q15sm575467pje.29 - gsmtp')
Process finished with exit code 1