如何使用python发送包含正文和附件的邮件
2个回答
展开全部
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib, datetime
#创建一个带附件的实例
msg = MIMEMultipart()
#构造附件
att = MIMEText(open('d:\\tc201.rar', 'rb').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="tc201.rar"'
msg.attach(att)
#加邮件头
msg['to'] = '备裤zhousl@xxx.com'
msg['from'] = 'zhousl@xxx.com'
msg['subject'] = Header('冒烟测试结果 (' + str(datetime.date.today()) + ')', \
'gb2312')
#发送邮件
server = smtplib.SMTP('smtp.xxx.com')
server.sendmail(msg['from'], msg['to'], \
散弯 冲滚闷msg.as_string())
server.close
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询