python发送邮件sendmail--smtplib【带附件】
来源:互联网 发布:网上报名软件 编辑:程序博客网 时间:2024/05/20 02:25
#!/usr/bin/env python# -*- coding: UTF-8 -*-from email.mime.multipart import MIMEMultipartfrom email.mime.base import MIMEBasefrom email.mime.text import MIMEText from email.utils import COMMASPACE,formatdatefrom email import encoders import os def send_mail(server, fro, to, subject, text, files=[]): assert type(server) == dict assert type(to) == list assert type(files) == list msg = MIMEMultipart() msg['From'] = fro msg['Subject'] = subject msg['To'] = COMMASPACE.join(to) #COMMASPACE==', ' msg['Date'] = formatdate(localtime=True) msg.attach(MIMEText(text)) for f in files: part = MIMEBase('application', 'octet-stream') #'octet-stream': binary data part.set_payload(open(f, 'rb').read()) encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f)) msg.attach(part) import smtplib smtp = smtplib.SMTP(server['name'], server['port']) smtp.ehlo() smtp.starttls() smtp.ehlo() smtp.login(server['user'], server['passwd']) smtp.sendmail(fro, to, msg.as_string()) smtp.close() if __name__=='__main__': server = {'name':'mail.server.com', 'user':'chenxiaowu', 'passwd':'xxxx', 'port':25} fro = 'chenxiaowu@163.com' to = ['xxxx@163.com'] subject = '脚本运行提醒' text = 'mail content' files = ['top_category.txt'] send_mail(server, fro, to, subject, text, files=files)
从网上找了些资料,不会有个别错误,上面代码经调试测试通过
1 0
- python发送邮件sendmail--smtplib【带附件】
- 使用python smtplib 发送带附件的邮件
- Sendmail 发送带附件的 html 邮件
- Python smtplib发送邮件 包含文本、附件、图片等
- Python模块探秘 Smtplib发送带有各种附件的邮件
- Python smtplib发送邮件 包含文本、附件、图片等
- #python# smtplib 邮件发送
- Python 邮件发送smtplib
- python smtplib 发送邮件
- python邮件发送带附件
- python+带附件发送邮件
- python发送带附件邮件
- python 使用smtplib发送带附件的email
- perl sendmail发送带附件的html邮件
- shell sendmail发送带附件的html格式邮件
- python 利用smtplib发送邮件
- Python使用smtplib发送邮件
- Python 发送带 附件 邮件 脚本
- 一个自增与自减的源码
- ComputerWorld 的 Richi Jennings
- 一篇postgresql和mysql的比较,网上搜的
- 使用spring boot构建web app
- Android中利用命令行进行截屏并导出到电脑上
- python发送邮件sendmail--smtplib【带附件】
- 网络最大流中一般增广路算法(标号法)
- PC指针的问题
- v4l2,camera笔记
- Assembly.Load()方法FileNotFound异常
- mysql按照任意格式倒出需要的字段
- require.js text 插件使用文档翻译
- Java3D 集成开发环境部署与配置(含实例)
- OpenCV基础数据结构