Example #1
0
    def _sendWithAttachment(self, receivers, title, content, attachment=None):
        # 设置eamil信息
        # 添加一个MIMEmultipart类,处理正文及附件
        message = MIMEMultipart()
        message['From'] = self.sender
        message['To'] = receivers[0]
        message['Subject'] = title
        part = MIMEApplication(open(attachment, 'rb').read())
        part.add_header('Content-Disposition',
                        'attachment',
                        filename=attachment)
        # 将内容附加到邮件主体中
        message.attach(MIMEText(content, 'plain', 'utf-8'))
        message.attach(part)

        # 登录并发送
        try:
            smtpObj = smtplib.SMTP_SSL(
            ) if self.sendType == "ssl" else smtplib.SMTP()
            smtpObj.connect(self.mailHost, self.mailPort)
            smtpObj.ehlo()
            if self.sendType == "tls":
                smtpObj.starttls()
            smtpObj.login(self.sender, self.passwd)
            smtpObj.sendmail(self.sender, receivers, message.as_string())
            Log.i(MailReporter.TAG,
                  'Mail successfully sent to ' + receivers[0])
            smtpObj.quit()
        except smtplib.SMTPException as e:
            Log.e(MailReporter.TAG, 'send() error', e)
Example #2
0
 def _sendText(self, receivers, title, content):
     # 设置email信息
     # 邮件内容设置
     message = MIMEText(content, 'plain', 'utf-8')
     # 邮件主题
     message['Subject'] = title
     # 发送方信息
     message['From'] = self.sender
     # 接受方信息
     message['To'] = receivers[0]
     try:
         smtpObj = smtplib.SMTP_SSL(
         ) if self.sendType == "ssl" else smtplib.SMTP()
         # 连接到服务器
         smtpObj.connect(self.mailHost, self.mailPort)
         smtpObj.ehlo()
         if self.sendType == "tls":
             smtpObj.starttls()
         # 登录到服务器
         smtpObj.login(self.sender, self.passwd)
         # 发送
         smtpObj.sendmail(self.sender, receivers, message.as_string())
         # 退出
         smtpObj.quit()
         Log.i(MailReporter.TAG,
               'Mail successfully sent to ' + receivers[0])
     except smtplib.SMTPException as e:
         Log.e(MailReporter.TAG, 'send() error', e)
Example #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 测试日志辅助类

import sys
sys.path.append("../")
from LogHelper import Log

TAG = "Test"

Log.d(TAG, "Hello")
Log.e(TAG, "World!")
Log.i(TAG, "Hehe")
Log.w(TAG, "XXXX")