python调用qq邮箱发送邮件
代码如下,需要qq邮箱开启授权码
import smtplib from email.mime.text import MIMEText from email.header import Header message = MIMEText('邮件内容') # 邮件内容 message['From'] = Header('xxx@qq.com') # 邮件发送者名字 message['To'] = Header('xxx@qq.com') # 邮件接收者名字 message['Subject'] = Header('邮件主题') # 邮件主题 mail = smtplib.SMTP() mail.connect("smtp.qq.com") # 连接 qq 邮箱 mail.login("xxx@qq.com", "授权码") # 账号和授权码 mail.sendmail("xxx@qq.com", ["xxx@qq.com"], message.as_string()) # 发送账号、接收账号和邮件信息