我想将一封电子邮件从一封电子邮件发送到另一封电子邮件。我运行这段代码
import smtplib
sender = "" # здесь я вписал свои электронные почты и пароль
recipient = ""
password = ""
subject = "Тестовое письмо из Python"
text = "Hello from Python"
smtp_server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
smtp_server.login(sender, password)
message = "Subject: {}\n\n{}".format(subject, text)
smtp_server.sendmail(sender, recipient, message)
smtp_server.close()
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 g11sm170351lfv.9 - gsmtp')
尽管我指定了正确的密码,但我在第 10 行得到了一个错误。
只允许应用程序在此处访问您的帐户
。很可能它应该对您有所帮助,
并从脚本发送信件的帐户中允许它
。甚至还有一篇关于此案例的文章,here