Esempio n. 1
0
def send(to_addrs, subject, plainText, textType='txt', attachs=[]):
    email_obj = MIMEMultipart()
    if textType == 'txt':
        msg = MIMEText(plainText)
    elif textType == 'html':
        msg = MIMEText(plainText, 'html', 'utf-8')
    from_addr = '*****@*****.**'
    email_obj.attach(msg)
    email_obj['Subject'] = subject
    email_obj['From'] = from_addr
    email_obj['To'] = ','.join(to_addrs)

    try:
        if attachs:
            for _atta in attachs:
                _, atta_name = os.path.split(_atta)
                atta = MIMEText(open(_atta, 'rb').read(), 'base64', 'utf-8')
                atta['Content-Type'] = 'application/octet-stream'
                atta[
                    'Content-Disposition'] = 'attachment;filename="%s"' % atta_name
                email_obj.attach(atta)
    except Exception as e:
        logger.debug('sendEmail add attachs error is %s' % (e))

    e_s = EmailSender(from_addr, to_addrs, email_obj)
    r_send = e_s.sendIt()
Esempio n. 2
0
def send(from_addr, to_addrs, subject, content):
    msg = MIMEMultipart()
    # from_addr = '*****@*****.**'
    msg['Subject'] = subject
    msg['From'] = from_addr
    msgText = MIMEText(content, 'html', 'utf-8')
    msg.attach(msgText)
    if type(to_addrs) == str:
        msg['To'] = to_addrs
    elif type(to_addrs) == list:
        msg['To'] = ','.join(to_addrs)

    e_s = EmailSender(from_addr, to_addrs, msg)
    r_send = e_s.sendIt()
    if r_send != {}:
        # s = smtplib.SMTP('corp.chinacache.com')
        s = smtplib.SMTP('anonymousrelay.chinacache.com')
        try:
            s.ehlo()
            s.starttls()
            s.ehlo()
        except Exception:
            pass
        # s.login('noreply', 'SnP123!@#')
        s.sendmail(from_addr, to_addrs, msg.as_string())
        s.quit()
Esempio n. 3
0
def send(from_addr, to_addrs, subject, content):
    # msg = MIMEText(content)
    msg = MIMEMultipart()
    # att1 = MIMEText(open('%scount_device_status_output%s.xls' % (LOG_DIR, date_str), 'rb').read(), \
    #                 'base64', 'utf-8')
    # att1['Content-Type'] = 'application/octet-stream'
    # att1['Content-Disposition'] = 'attachment;filename="%scount_device_status_output%s.xls"' % (LOG_DIR, date_str)
    # msg.attach(att1)
    # from_addr = '*****@*****.**'
    msg['Subject'] = subject
    msg['From'] = from_addr
    msgText = MIMEText(content, 'html', 'utf-8')
    msg.attach(msgText)
    if type(to_addrs) == str:
        msg['To'] = to_addrs
    elif type(to_addrs) == list:
        msg['To'] = ','.join(to_addrs)

    e_s = EmailSender(from_addr, to_addrs, msg)
    r_send = e_s.sendIt()
    if r_send != {}:
        # s = smtplib.SMTP('corp.chinacache.com')
        s = smtplib.SMTP('anonymousrelay.chinacache.com')
        try:
            s.ehlo()
            s.starttls()
            s.ehlo()
        except Exception:
            pass
        # s.login('noreply', 'SnP123!@#')
        s.sendmail(from_addr, to_addrs, msg.as_string())
        s.quit()
Esempio n. 4
0
def send(from_addr, to_addrs, subject, content, timestamp, type_flag=1):
    msg = MIMEMultipart()
    try:
        # all url accessories
        att1 = MIMEText(open('%sall_%s.txt' % (LOG_DIR_ALL, timestamp), 'rb').read(), \
                        'base64', 'utf-8')
        att1['Content-Type'] = 'application/octet-stream'
        att1[
            'Content-Disposition'] = 'attachment;filename="all_%s.txt"' % timestamp
        msg.attach(att1)

        # all failed url accessories
        if type_flag == 1:
            att2 = MIMEText(open('%sfailed_%s.txt' % (LOG_DIR_FAILED, timestamp), 'rb').read(), \
                            'base64', 'utf-8')
            att2['Content-Type'] = 'application/octet-stream'
            att2[
                'Content-Disposition'] = 'attachment;filename="failed_%s.txt"' % timestamp
            msg.attach(att2)
    except Exception:
        logger.debug('send email, acquisition attachment error:%s' %
                     traceback.format_exc())
    # from_addr = '*****@*****.**'
    msg['Subject'] = subject
    msg['From'] = from_addr
    msgText = MIMEText(content, 'html', 'utf-8')
    msg.attach(msgText)
    if type(to_addrs) == str:
        msg['To'] = to_addrs
    elif type(to_addrs) == list:
        msg['To'] = ','.join(to_addrs)
    e_s = EmailSender(from_addr, to_addrs, msg)
    r_send = e_s.sendIt()
    if r_send != {}:
        # s = smtplib.SMTP('corp.chinacache.com')
        s = smtplib.SMTP('anonymousrelay.chinacache.com')
        try:
            s.ehlo()
            s.starttls()
            s.ehlo()
        except Exception:
            logger.debug('send email error:%s' % traceback.format_exc())
        # s.login('noreply', 'SnP123!@#')
        s.sendmail(from_addr, to_addrs, msg.as_string())
        s.quit()
Esempio n. 5
0
def send(to_addrs, subject, plainText, textType='txt', attachs=[]):
    email_obj = MIMEMultipart()
    if textType == 'txt':
        msg = MIMEText(plainText)
    elif textType == 'html':
        msg = MIMEText(plainText, 'html', 'utf-8')
    from_addr = '*****@*****.**'
    email_obj.attach(msg)
    email_obj['Subject'] = subject
    email_obj['From'] = from_addr
    email_obj['To'] = ','.join(to_addrs)

    try:
        if attachs:
            for _atta in attachs:
                _, atta_name = os.path.split(_atta)
                atta = MIMEText(open(_atta, 'rb').read(), 'base64', 'utf-8')
                atta['Content-Type'] = 'application/octet-stream'
                atta[
                    'Content-Disposition'] = 'attachment;filename="%s"' % atta_name
                email_obj.attach(atta)
    except Exception:
        logger.debug('sendEmail add attachs error is %s' % (e))

    e_s = EmailSender(from_addr, to_addrs, email_obj)
    r_send = e_s.sendIt()
    if r_send != {}:

        try:
            #s = smtplib.SMTP('corp.chinacache.com')
            s = smtplib.SMTP('anonymousrelay.chinacache.com')
            s.ehlo()
            s.starttls()
            s.ehlo()
        except:
            logger.debug("%s STARTTLS extension not supported by server" %
                         email_obj['To'])
            pass
        #s.login('noreply', 'SnP123!@#')
        s.sendmail(from_addr, to_addrs, email_obj.as_string())
        s.quit()
                            'base64', 'utf-8')
            att2['Content-Type'] = 'application/octet-stream'
            att2['Content-Disposition'] = 'attachment;filename="failed_%s.txt"' % timestamp
            msg.attach(att2)
    except Exception, e:
        logger.debug('send email, acquisition attachment error:%s' % traceback.format_exc(e))
    # from_addr = '*****@*****.**'
    msg['Subject'] = subject
    msg['From'] = from_addr
    msgText = MIMEText(content, 'html', 'utf-8')
    msg.attach(msgText)
    if type(to_addrs) == str:
        msg['To'] = to_addrs
    elif type(to_addrs) == list:
        msg['To'] = ','.join(to_addrs)
    e_s = EmailSender(from_addr, to_addrs, msg)
    r_send = e_s.sendIt()
    if r_send != {}:
        # s = smtplib.SMTP('corp.chinacache.com')
        s = smtplib.SMTP('anonymousrelay.chinacache.com')
        try:
            s.ehlo()
            s.starttls()
            s.ehlo()
        except Exception, ex:
            logger.debug('send email error:%s' % traceback.format_exc(ex))
        # s.login('noreply', 'SnP123!@#')
        s.sendmail(from_addr, to_addrs, msg.as_string())
        s.quit()