SMTPAuthenticationError code 535 with python - PullRequest
0 голосов
/ 10 июля 2020

Я пробовал с «разрешить менее безопасное приложение» и «unlockCaptcha», но все равно не работал. Как узнать, проблема в моей учетной записи или в коде? Спасибо за внимание, вот код:

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib

# Import the email modules we'll need
from email.message import EmailMessage

# create message object instance
msg = MIMEMultipart()
 
message = "Prova"

# setup the parameters of the message
password="pass"
msg['From'] = "senders@example.com"
msg['To'] = "receiver@example.com"
msg['Subject'] = "Prova"

# add in the message body
msg.attach(MIMEText(message, 'plain'))
 
#create server
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
# Login Credentials for sending the mail
server.login(msg['From'], password)

# send the message via the server.
server.sendmail(msg['From'], msg['To'], msg.as_string())
 
server.quit()
 
print(f"successfully sent email to {msg['To']}")
...