1 到邮箱页面

gmail smtp python发送邮件-LMLPHP

2 已经开启谷歌Gmail邮箱的IMAP服务了,谷歌邮箱机制是IMAP一旦开通,SMTP也就自动开通了,设置里没有没关系,不用管它。

gmail smtp python发送邮件-LMLPHP

3 到账号设置页面

3.1 设置两步验证 

https://www.cnblogs.com/jiyuwu/p/16313476.html

3.2 设置专用密码

gmail smtp python发送邮件-LMLPHP

4 python代码

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

# 设置发件人邮箱地址和密码
sender_email = "my@gmail.com"
app_password = "aaaa cccc dddd 0000"

# 设置收件人邮箱地址
receiver_email = "xxxx@qq.com"

# 创建邮件内容
message = MIMEMultipart()
message["From"
02-17 23:26