python实现smtp发送邮件类-直接调用就好
2015-09-22 16:23
537 查看
python实现smtp发送邮件类
使用方法#使用方法Sendmail('stmp服务器', '邮箱', '密码', 发送的邮箱用list格式,可多个发送) p = Sendmail('smtp.minshengec.cn', 'wangqi@minshengec.cn', 'xxoofor you', ['wangqi@minshengec.cn']) #setMailInfo('标题', '内容') p.setMailInfo('dsadsa', 'xxoo') #最后运行run方法 p.run()
#!/usr/bin/env python # -*- coding: gbk -*- #导入smtplib和MIMEText import smtplib from email.mime.text import MIMEText class Sendmail(object): def __init__(self, mailHost, mailUser, mailPwd): self.mailHost = mailHost; self.mailUser = mailUser; self.mailPwd = mailPwd; self.sendList = []; #function subject->title def setMailInfo(self, sendList,subject, content): self.sendList = sendList self.content = content; self.subject = subject; self.msg = MIMEText(self.content) self.msg['From'] = self.mailUser self.msg['Subject'] = self.subject self.msg['To'] = ";".join(self.sendList) def run(self): try: self.send = smtplib.SMTP() self.send.connect(self.mailHost) self.send.login(self.mailUser, self.mailPwd) self.send.sendmail(self.mailUser, self.sendList, self.msg.as_string()) print '[*]-----send mail---to' + str(self.sendList) + 'success-----[*]' except smtplib.SMTPException as e: print e #p = Sendmail('smtp.minshengec.cn', 'wangqi@minshengec.cn', 'xxoo for you') #p.setMailInfo(['wangqi@minshengec.cn'], 'dsadsaqqq', 'xxodsado') #p.run()
相关文章推荐
- python socket 模块
- Python Socket学习
- python之web模块学习-- urllib2
- Python定时任务框架APScheduler 3.0.3 Cron示例
- Python中创建一个多维数组的方法
- Python之数据类型 一
- Python之数据类型 一
- Python监控主机是否存活并以邮件报警
- 树莓派的gpio python使用
- python matplotlib 机器学习,作图命令
- python之entry points
- Python 拉丁超立方采样
- 【已解决】安装pyleus遇到的'bdist_wheel'错误
- 使用python抓取百度搜索、百度新闻搜索的关键词个数
- python之字符串的操作和使用
- python执行系统命令的几种方法
- python-time
- Python脚本10 —— 复制json文件并替换指定字段
- Python脚本09 —— 一个计算题
- Python脚本08 —— 获取七牛服务器加密后的url