1 到邮箱页面
2 已经开启谷歌Gmail邮箱的IMAP服务了,谷歌邮箱机制是IMAP一旦开通,SMTP也就自动开通了,设置里没有没关系,不用管它。
3 到账号设置页面
3.1 设置两步验证
https://www.cnblogs.com/jiyuwu/p/16313476.html
3.2 设置专用密码
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"] = sender_email
message["To"] = receiver_email
message["Subject"] = "Python SMTP Test1"# 邮件正文内容
body = "This is a test email sent from Python using SMTP."
message.attach(MIMEText(body, "plain"))# 连接到Gmail的SMTP服务器
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(sender_email, app_password)# 发送邮件
server.sendmail(sender_email, receiver_email, message.as_string())# 关闭连接
server.quit()print("Email sent successfully!")
参考:
https://www.cnblogs.com/jiyuwu/p/16313476.html