Python发邮件代码
2013-04-17 16:05
190 查看
class BaseMail: def __init__(self,smtp,bSmtpAuth, sender, pwd): self.smtp = smtp; self.bSmtpAuth = bSmtpAuth; self.sender = sender; self.pwd = pwd; def _parserSend(self, sSubject, sContent, lsPlugin): return sSubject, sContent, lsPlugin; def send ( self, sSubject, sContent, lsTo, lsCc = [], lsPlugin = [] ): mit = MIMEMultipart(); mit['from'] = self.sender; mit['to'] = ','.join( lsTo ); if lsCc: mit['cc'] = ','.join( lsCc ); codeSubject, codeContent, codePlugin = self._parserSend(sSubject, sContent, lsPlugin); mit.attach( MIMEText( codeContent, 'html', 'utf-8' ) ); mit['subject'] = codeSubject; for plugin in codePlugin: mitFile = MIMEApplication( plugin['content'], ); mitFile.add_header( 'content-disposition', 'attachment', filename=plugin['subject'] ); mit.attach( mitFile ); server = smtplib.SMTP( self.smtp ); if self.bSmtpAuth: server.docmd( "EHLO server" ); server.ehlo(); server.esmtp_features['auth'] = 'LOGIN DIGEST-MD5 PLAIN'; #server.starttls(); server.login( self.sender, self.pwd ); server.sendmail( self.sender, lsTo , mit.as_string() ); server.close(); class VanclMail(BaseMail): def __init__( self, sender, pwd ): BaseMail.__init__( self, 'SMTP', True, sender, pwd ); self.__strcode = 'utf-8'; def _parserSend(self, sSubject, sContent, lsPlugin): for i in lsPlugin: i['subject'] = i['subject'].encode(self.__strcode); return sSubject.encode(self.__strcode), sContent.encode(self.__strcode), lsPlugin; class NetEase(BaseMail): def __init__( self, sender, pwd ): BaseMail.__init__( self, 'smtp.163.com', True, sender, pwd ); self.__strcode = 'utf-8'; def _parserSend(self, sSubject, sContent, lsPlugin): '''for i in lsPlugin: i['subject'] = i['subject'].encode(self.__strcode);''' return sSubject.encode(self.__strcode), sContent.encode(self.__strcode), lsPlugin;
相关文章推荐
- python发邮件的代码
- python自动发邮件库yagmail的示例代码
- python3 SMTP 发邮件 通过测试完整代码
- 简单的python smtp发邮件代码
- python发邮件的 代码
- 使用python smtp发邮件代码
- 15行Python代码带你轻松理解令牌桶算法
- 第一个python代码
- Python代码运行助手
- python实现壁纸批量下载代码实例
- Python 获取 网易云音乐热门评论(python2/python3代码)
- python 布尔操作实现代码
- 隐马模型Python代码
- Python字典,函数,全局变量代码解析
- autopep8规范你的python代码
- python 生成目录树及显示文件大小的代码
- Python 代码性能优化技巧
- CentOS6.4升级Python到2.7版本 , 用vim写python代码
- 新建从网页拷贝代码的python文件保存不了的解决方案
- python爬虫代码-CSDN博客下载