用python发送邮件的简单工具

PyMailMan的Python项目详细描述


用python发送邮件的简单工具

安装

sudo pip install PyMailMan

用法

  • 发送文本
fromPyMailManimportPyMailManmail=PyMailMan(host='smtp.qq.com',user='12345678',password='12345678')mail.send(['3456767@qq.com','testman@gmail.com'],'This is title','This is the content')print'OK'ifmail.statuselsemail.errMsg
  • 发送HTML
fromPyMailManimportPyMailManmail=PyMailMan(host='smtp.qq.com',user='12345678',password='12345678')mail.send(['3456767@qq.com','testman@gmail.com'],'This is title',"<p style='color:red'>This is the content</p>")print'OK'ifmail.statuselsemail.errMsg
  • 用文件发送电子邮件
fromPyMailManimportPyMailManmail=PyMailMan(host='smtp.qq.com',user='12345678',password='12345678')#Recommand to write the absolute path of the filemail.send(['3456767@qq.com','testman@gmail.com'],'This is title','This is the content','/home/kongkongyzt/a.txt','/home/kongkongyzt/b.txt')print'OK'ifmail.statuselsemail.errMsg
  • 在邮件内容中显示图像
mail=PyMailMan(host='smtp-mail.outlook.com',user='xxxxx@outlook.com',password='xxxx')mail.send(['783087000@qq.com'],'This is title',"Hello,The following image is the photo of last vacation in China, do you <span style='color:red'>like</span> it ? <img src='cid:1'>","/home/kongkongyzt/a.jpg","/home/kongkongyzt/b.docx","/home/kongkongyzt/c.jpg")print'OK'ifmail.statuselsemail.errMsg

需要注意的是,cid:1中的1表示 你的附件,在这个例子中是/home/kongkongyzt/c.jpg,你应该 也要知道,一旦你在附件中选择了一个图片 使用图像文件<img src='cid:xx'>在邮件内容中显示 不会出现在邮件的附件列表中

公用邮件SMTP配置示例

假设电子邮件地址是1234567@xx.com,密码是12345678 是否有一些SMTP配置示例:

  • QQ邮件
PyMailMan(host='smtp.qq.com',user='1234567',password='12345678')
  • Gmail
PyMailMan(host='smtp.gmail.com',user='1234567@gmail.com',password='12345678')
  • 展望
PyMailMan(host='smtp-mail.outlook.com',user='1234567@outlook.com',password='12345678')

提示

  • 您可以手动定义端口和前缀
PyMailMan(host='smtp.gmail.com',user='1234567@gmail.com',password='12345678',ports=25,prefix='gmail.com')

反馈

如果您有任何问题,请通过打开问题与我联系 在Github主页上: https://github.com/kongkongyzt/PyMailMan

更改日志

  • 0.1

初始化提交

  • 0.2

添加“通过HTML发送”和“通过文件错误修复发送”

  • 0.9

错误修复

  • 1.0

添加对发送具有相对路径的文件的支持设置附加文件 名称作为其“真实文件名”

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为jvm使用所有可用的系统内存   java:将值应用于列、3d数组   安卓 studio中我的应用程序的java生成异常   java地图上的视图是什么意思?   java是表示棋盘最有效的方法   java如何防止jackson在反序列化中实例化新对象   有没有办法禁用在java小程序中发送SNI记录?   java如何在递归函数的每一级都有一个新的局部数组   java如何使用JDT构建调用图   utf 8 Java字符编码,ISO到utf转换   java交错两个数组   java无法将GetMethodID与JNI中的字节数组参数一起使用   使用muledomainmavenplugin发布时的java双上传   java退出或退出actionListener   java我可以在Struts 2中的隐藏字段中保留对象引用吗?   java如何让Checkstyle忽略用@Entity注释标记的类的最终方法规则?   文件io java。木卫一。FileNotFoundException错误   java根据给定的条件从ArrayList中删除对象   安卓 SetId()和java中的findviewById以编程方式发布   java在JSP中显示字符串值