用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
添加对发送具有相对路径的文件的支持设置附加文件 名称作为其“真实文件名”