【发布时间】:2020-07-12 08:48:25
【问题描述】:
我正在尝试发送电子邮件,但遇到了以下错误:
smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific password required. Learn more at\n5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor d2sm13023190qkl.98 - gsmtp')
在网址中我没有看到任何超级有用的东西,有人有什么建议吗?出于这样的目的,我将电子邮件帐户密码保留为test,而不是分享我的个人信息..
import smtplib
import ssl
# User configuration
sender_email = 'test@gmail.com'
receiver_email = 'test@gmail.com'
password = 'test'
# Email text
email_body = '''
This is a test email sent by Python. Isn't that cool?
'''
# Creating a SMTP session | use 587 with TLS, 465 SSL and 25
server = smtplib.SMTP('smtp.gmail.com', 587)
# Encrypts the email
context = ssl.create_default_context()
server.starttls(context=context)
# We log in into our Google account
server.login(sender_email, password)
# Sending email from sender, to receiver with the email body
server.sendmail(sender_email, receiver_email, email_body)
print('Email sent!')
print('Closing the server...')
server.quit()
【问题讨论】:
-
“需要应用程序专用密码”——你有吗?
-
你应该考虑使用正式的gmail API
-
我在我的 gmail 帐户中运行了此页面中的示例并且它有效:julien.danjou.info/…
-
目前 Gmail 比其他邮件服务器更受限制,每个应用程序都需要自己的密码才能访问邮件。