# Path: src/utils/tool.py
# class DO(dict):
#     def __getattr__(self, name):
# def ip_check(ip):
# def email_check(email):
# def ParseMySQL(mysql, callback="dict"):
# def UploadImage2Upyun(FilePath, FileData, kwargs=PLUGINS['UpYunStorage']):
# def UploadRealFile2Upyun(file, imgurl, kwargs=PLUGINS['UpYunStorage']):
# def BaiduActivePush(pushUrl, original=True, callUrl=PLUGINS['BaiduActivePush']['callUrl']):
# def ChoiceColor():
# def TagRandomColor():
# def getIpArea(ip):
# def getIpArea2(ip):
# def get_current_timestamp():
# def timestamp_after_timestamp(timestamp=None, seconds=0, minutes=0, hours=0, days=0):
# def timestamp_to_timestring(timestamp, format='%Y-%m-%d %H:%M:%S'):
# def url_check(addr):
# def sql_safestring_check(string):
# def formatSize(bytes):
# def make_zipfile(zip_filename, zip_path, exclude=[]):
# def str_count(str):
#         M = kb / 1024
#             G = M / 1024


import smtplib
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
from .tool import email_check, logger
from config import EMAIL
        return formataddr((Header(name, 'utf-8').encode(), addr))

    def SendMessage(self, to_addr, subject, message, formatType="plain"):
        """
        发送文本/HTML消息
        @param to_addr(str, unicode, list, tuple) 收件人地址，多个收件人请使用列表或元组
        @param subject(str, unicode) 主题
        @param message(str, unicode) 邮件正文
        @param formatType(str, unicode)  邮件格式类型 plain或html
        """
        res = dict(success=False)
        if subject and message and isinstance(subject, (str, unicode)) and isinstance(message, (str, unicode)) and isinstance(to_addr, (str, unicode, list, tuple)):
            if isinstance(to_addr, (str, unicode)):
                to_addrs = (to_addr,)
            else:
                to_addrs = to_addr
            msg = MIMEText(message, formatType, 'utf-8')
            msg['From'] = self.from_addr
            msg['To'] = to_addr
            msg['Subject'] = Header(subject, 'utf-8').encode()
            try:
                if self.smtp_ssl is True:
                    server = smtplib.SMTP_SSL(self.smtp_server, port=self.smtp_port)
                else:
                    server = smtplib.SMTP(self.smtp_server, port=self.smtp_port)
                # server.set_debuglevel(1)
                server.login(self.useraddr, self.password)
                server.sendmail(self.useraddr, to_addrs, msg.as_string())
                server.quit()
            except smtplib.SMTPException, e:

# Path: src/utils/tool.py
# class DO(dict):
#     def __getattr__(self, name):
# def ip_check(ip):
# def email_check(email):
# def ParseMySQL(mysql, callback="dict"):
# def UploadImage2Upyun(FilePath, FileData, kwargs=PLUGINS['UpYunStorage']):
# def UploadRealFile2Upyun(file, imgurl, kwargs=PLUGINS['UpYunStorage']):
# def BaiduActivePush(pushUrl, original=True, callUrl=PLUGINS['BaiduActivePush']['callUrl']):
# def ChoiceColor():
# def TagRandomColor():
# def getIpArea(ip):
# def getIpArea2(ip):
# def get_current_timestamp():
# def timestamp_after_timestamp(timestamp=None, seconds=0, minutes=0, hours=0, days=0):
# def timestamp_to_timestring(timestamp, format='%Y-%m-%d %H:%M:%S'):
# def url_check(addr):
# def sql_safestring_check(string):
# def formatSize(bytes):
# def make_zipfile(zip_filename, zip_path, exclude=[]):
# def str_count(str):
#         M = kb / 1024
#             G = M / 1024


# Path: src/utils/send_email_msg.py
import smtplib
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
from .tool import email_check, logger
from config import EMAIL

        return formataddr((Header(name, 'utf-8').encode(), addr))

    def SendMessage(self, to_addr, subject, message, formatType="plain"):
        """
        发送文本/HTML消息
        @param to_addr(str, unicode, list, tuple) 收件人地址，多个收件人请使用列表或元组
        @param subject(str, unicode) 主题
        @param message(str, unicode) 邮件正文
        @param formatType(str, unicode)  邮件格式类型 plain或html
        """
        res = dict(success=False)
        if subject and message and isinstance(subject, (str, unicode)) and isinstance(message, (str, unicode)) and isinstance(to_addr, (str, unicode, list, tuple)):
            if isinstance(to_addr, (str, unicode)):
                to_addrs = (to_addr,)
            else:
                to_addrs = to_addr
            msg = MIMEText(message, formatType, 'utf-8')
            msg['From'] = self.from_addr
            msg['To'] = to_addr
            msg['Subject'] = Header(subject, 'utf-8').encode()
            try:
                if self.smtp_ssl is True:
                    server = smtplib.SMTP_SSL(self.smtp_server, port=self.smtp_port)
                else:
                    server = smtplib.SMTP(self.smtp_server, port=self.smtp_port)
                # server.set_debuglevel(1)
                server.login(self.useraddr, self.password)
                server.sendmail(self.useraddr, to_addrs, msg.as_string())
                server.quit()
            except smtplib.SMTPException, e:

                logger.sys.error(e, exc_info=True)