zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Python 发送带附件的email详解编程语言

Python编程语言 详解 发送 email 附件
2023-06-13 09:20:23 时间
from email.MIMEText import MIMEText 

from email.MIMEMultipart import MIMEMultipart 

import smtplib 

mail_host = smtp.126.com 

mail_user = [email protected] 

mail_pwd = xx 

mail_to = [email protected] 


att = MIMEText(open(d://a.txt,rb).read(),base64,gb2312) att["Content-Type"] = application/octet-stream att["Content-Disposition"] = attachment;filename="hello.txt" msg.attach(att) message = content part body = MIMEText(message) msg.attach(body) msg[To] = mail_to msg[from] = mail_user msg[subject] = this is a python test mail try: s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pwd) s.sendmail(mail_user,mail_to,msg.as_string()) s.close() print success except Exception,e: print e

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8197.html

cjavapython