Python SMTP协议发送QQ邮件

来源:互联网 发布:python交换两个值 编辑:程序博客网 时间:2024/06/02 21:52
from email.header import Headerfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimport smtplib, datetimemsg = MIMEMultipart()att = MIMEText(open('d:\\mm1.jpg', 'rb').read(), 'base64', 'gb2312')att["Content-Type"] = 'application/octet-stream'att["Content-Disposition"] = 'attachment; filename="zhanghongwei.jpg"'msg.attach(att)msg['to'] = '844398850@qq.com'msg['from'] = '348632061@qq.com'msg['subject'] = Header('testABC (' + str(datetime.date.today()) + ')','gb2312')server = smtplib.SMTP('smtp.qq.com')server.login('348632061','xyz')error=server.sendmail(msg['from'], msg['to'], msg.as_string())server.close()print(error)

原创粉丝点击