python实现简单的发送邮件
2020-12-13 02:27
标签:smtp ssl html log ring print 服务 bsp import import smtplib python实现简单的发送邮件 标签:smtp ssl html log ring print 服务 bsp import 原文地址:https://www.cnblogs.com/wsfsd/p/11038869.html
from email.mime.text import MIMEText
smtpserver = "smtp.qq.com"
port =465
sender = "发件人账号@qq.com"
psw = "smtp服务的授权码"
receiver ="收件人账号@qq.com"
body = ‘
‘
msg = MIMEText(body,‘html‘,"utf-8")
msg[‘from‘] = sender
msg[‘to‘] = receiver
msg[‘subject‘] = "发送的内容 "
try:
smtp = smtplib.SMTP_SSL(smtpserver, port)
smtp.login(sender, psw)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
print(‘success‘)
except smtplib.SMTPException:
print(‘ERRO‘)