python+带附件发送邮件

来源:互联网 发布:阿里云如何关闭网站 编辑:程序博客网 时间:2024/05/26 02:52

1.其他类似方法寻找附件和添加附件主题::用到email和smtp里面的方法,这里就不说了

2.主要说一下 怎么样把发送携带附件的邮件:代码附上

# 构造MIMEBase对象做为文件附件内容并附加到根容器ctype,encoding = mimetypes.guess_type(file_new)if ctype is None or encoding is not None:  ctype='application/octet-stream'maintype,subtype = ctype.split('/',1)file_msg=email.MIMEImage.MIMEImage(open(file_new,'rb').read(),subtype)

原创粉丝点击