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

the error

Here is what I tried so far:

  • allowed less secure apps
  • waited for 1 hour after allowing
Asked By: Mustafa Issa

||

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.

Another option would be to use xoauth2.

Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.