标签: google-2fa

如何使用 2 因素身份验证从 python 发送电子邮件?

我创建了 python 文件,可以使用打开的不太安全的应用程序发送电子邮件,但我需要将其关闭。如何使用 2FA 发送电子邮件?

# import simple mail transfer protocol library
import smtplib 

# import EmailMessage method
from email.message import EmailMessage

contacts = ['<email@email.com>', '<email2@email.com>']
EMAIL_ADDRESS = '<my_gmail>'
EMAIL_PASSWORD = '<my_gmail_password>'

# Create empty Email Message object
msg = EmailMessage()
msg['Subject'] = 'Automated python email sender 5'
msg['From'] = EMAIL_ADDRESS
msg['To'] = contacts
msg.set_content('<sample_content>')

# contact manager we will make sure our connection is closed automatically without us doing it manually
# 465 is the port number for plain …
Run Code Online (Sandbox Code Playgroud)

python email gmail smtp google-2fa

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

email ×1

gmail ×1

google-2fa ×1

python ×1

smtp ×1