(self, strTitle, strContent, listToAddr, **kwargs)
发送邮件
发送邮件
发送邮件
def _send(self, strTitle, strContent, listToAddr, **kwargs):
        '''''
            发送邮件
        '''
        # 构造MIMEMultipart对象做为根容器
        main_msg = email.mime.multipart.MIMEMultipart()

        # 添加文本内容
        text_msg = email.mime.text.MIMEText(strContent, 'plain', 'utf-8')
        main_msg.attach(text_msg)

        # 添加附件
        filename_list = kwargs.get('filename_list')
        if filename_list:
            for filename in kwargs['filename_list']:
                file_msg = self._add_attachment(filename)
                main_msg.attach(file_msg)

        # 收发件人地址和邮件标题:
        main_msg['From'] = formataddr(["archer 通知", self.MAIL_REVIEW_FROM_ADDR])
        main_msg['To'] = ','.join(listToAddr)
        listCcAddr = kwargs.get('listCcAddr')
        if listCcAddr:
            main_msg['Cc'] = ', '.join(kwargs['listCcAddr'])
            listAddr = listToAddr + listCcAddr
        else:
            listAddr = listToAddr
        main_msg['Subject'] = Header(strTitle, "utf-8").encode()
        main_msg['Date'] = email.utils.formatdate()

        if self.SSL:
            server = smtplib.SMTP_SSL(self.MAIL_REVIEW_SMTP_SERVER, self.MAIL_REVIEW_SMTP_PORT)  # SMTP协议默认SSL端口是465
        else:
            server = smtplib.SMTP(self.MAIL_REVIEW_SMTP_SERVER, self.MAIL_REVIEW_SMTP_PORT)  # SMTP协议默认端口是25
        # server.set_debuglevel(1)

        # 如果提供的密码为空，则不需要登录SMTP server
        if self.MAIL_REVIEW_FROM_PASSWORD != '':
            server.login(self.MAIL_REVIEW_FROM_ADDR, self.MAIL_REVIEW_FROM_PASSWORD)
        sendResult = server.sendmail(self.MAIL_REVIEW_FROM_ADDR, listAddr, main_msg.as_string())
        server.quit()
def _send ( self , strTitle , strContent , listToAddr , * * kwargs ) : # 构造MIMEMultipart对象做为根容器 main_msg = email . mime . multipart . MIMEMultipart ( ) # 添加文本内容 text_msg = email . mime . text . MIMEText ( strContent , 'plain' , 'utf-8' ) main_msg . attach ( text_msg ) # 添加附件 filename_list = kwargs . get ( 'filename_list' ) if filename_list : for filename in kwargs [ 'filename_list' ] : file_msg = self . _add_attachment ( filename ) main_msg . attach ( file_msg ) # 收发件人地址和邮件标题: main_msg [ 'From' ] = formataddr ( [ "archer 通知", se l .MAI L _REVIEW_FROM_ADDR]) main_msg [ 'To' ] = ',' . join ( listToAddr ) listCcAddr = kwargs . get ( 'listCcAddr' ) if listCcAddr : main_msg [ 'Cc' ] = ', ' . join ( kwargs [ 'listCcAddr' ] ) listAddr = listToAddr + listCcAddr else : listAddr = listToAddr main_msg [ 'Subject' ] = Header ( strTitle , "utf-8" ) . encode ( ) main_msg [ 'Date' ] = email . utils . formatdate ( ) if self . SSL : server = smtplib . SMTP_SSL ( self . MAIL_REVIEW_SMTP_SERVER , self . MAIL_REVIEW_SMTP_PORT ) # SMTP协议默认SSL端口是465 else : server = smtplib . SMTP ( self . MAIL_REVIEW_SMTP_SERVER , self . MAIL_REVIEW_SMTP_PORT ) # SMTP协议默认端口是25 # server.set_debuglevel(1) # 如果提供的密码为空，则不需要登录SMTP server if self . MAIL_REVIEW_FROM_PASSWORD != '' : server . login ( self . MAIL_REVIEW_FROM_ADDR , self . MAIL_REVIEW_FROM_PASSWORD ) sendResult = server . sendmail ( self . MAIL_REVIEW_FROM_ADDR , listAddr , main_msg . as_string ( ) ) server . quit ( )