Why when I compile I get username and password are not accepted?
Question:
Here is the code that I want to compile
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
import smtplib
def send_mail(email, password, text):
server = smtplib.SMTP_SSL("smtp.gmail.com:465")
server.login(email, password)
server.sendmail(email, email, text)
text = msg.as_string()
server.quit()
f = open("c1.png")
send_mail("[email protected]","xxxxxxxx",f)
and the output
Here is what I tried so far:
- allowed less secure apps
- waited for 1 hour after allowing
Answers:
Try to generate a password from apps password and use that code instead of the users actual password.
An App Password is a 16-digit passcode that gives an app or device restricted access to your Google Account without having to divulge your personal password and complete access to your Google Account.
more info on Sign in with App Passwords
This is normally due to the user having 2fa enabled.
- How I send emails with Python. In 2.2 minutes flat!
- How I fixed fix for SMTP username and password not accepted error.
Another option would be to use xoauth2.
Here is the code that I want to compile
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
import smtplib
def send_mail(email, password, text):
server = smtplib.SMTP_SSL("smtp.gmail.com:465")
server.login(email, password)
server.sendmail(email, email, text)
text = msg.as_string()
server.quit()
f = open("c1.png")
send_mail("[email protected]","xxxxxxxx",f)
and the output
Here is what I tried so far:
- allowed less secure apps
- waited for 1 hour after allowing
Try to generate a password from apps password and use that code instead of the users actual password.
An App Password is a 16-digit passcode that gives an app or device restricted access to your Google Account without having to divulge your personal password and complete access to your Google Account.
more info on Sign in with App Passwords
This is normally due to the user having 2fa enabled.
- How I send emails with Python. In 2.2 minutes flat!
- How I fixed fix for SMTP username and password not accepted error.
Another option would be to use xoauth2.