import smtplib from email.mime.text import MIMEText from email.header import Header smtp = "smtp.qq.com" sender = "2282310940@qq.com" receiver = "1328497946@qq.com" # pwd = "" pwd = ‘你的授权码‘ title = "邮件的标题" contents = "邮件内容" try: message = MIMEText(contents, "plain", "utf-8") message[‘From‘] = Header(sender, "utf-8") message[‘To‘] = Header(receiver, "utf-8") message[‘Subject‘] = Header(title, "utf-8") opt = smtplib.SMTP_SSL(smtp, 465) opt.login(sender, pwd) opt.sendmail(sender, receiver, message.as_string()) opt.quit() print("邮件发送成功") except Exception as e: print(e)
测试一下,发送成功。
原文:https://www.cnblogs.com/1328497946TS/p/11938517.html