• Python递归次数统计写法及邮件发送失败后的重新发送


    Python递归次数统计写法及邮件发送失败后的重新发送

    
    def send(file_list,receivers,subject,acc,times=0):
        username = "xxxxxxx" 
        password = "ppppppp"
        sender = username
        receivers = receivers
        # 如名字所示: Multipart就是多个部分
        msg = MIMEMultipart()
        msg['Subject'] = subject
        msg['From'] = sender
        msg['To'] = ','.join(receivers)
        msg['Cc'] = acc
        #下面是文字部分,也就是纯文本
        context = """
        
        
            

    HELLO:

    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    """
    puretext = MIMEText(context,'html', 'utf-8') msg.attach(puretext) # 下面是附件部分 ,这里分为了好几个类型 # 首先是xlsx类型的附件 for i in file_list: filename = i.strip() att1 = MIMEText(open(filename, 'rb').read(), 'base64', 'utf-8') att1["Content-Type"] = 'application/octet-stream' att1["Content-Disposition"] = 'attachment; filename=%s'%filename.split("/")[-1] msg.attach(att1) # # jpg类型的附件 # jpgpart = MIMEApplication(open('beauty.jpg', 'rb').read()) # jpgpart.add_header('Content-Disposition', 'attachment', filename='beauty.jpg') # msg.attach(jpgpart) # # mp3类型的附件 # mp3part = MIMEApplication(open('kenny.mp3', 'rb').read()) # mp3part.add_header('Content-Disposition', 'attachment', filename='benny.mp3') # msg.attach(mp3part) ## 下面开始真正的发送邮件了 print '下面开始真正的发送邮件了' print('times:',times) try: try: client = smtplib.SMTP_SSL('mail.xxxx.com','465') client.login(username, password) client.sendmail(sender, receivers, msg.as_string()) client.quit() print '带有各种附件的邮件发送成功!' except Exception as er: print 'er::',er print 'Send again::', subject time.sleep(1) times += 1 if times<=10: send(file_list, receivers, subject, acc,times=times) except smtplib.SMTPRecipientsRefused: print 'Recipient refused' except smtplib.SMTPAuthenticationError: print 'Auth error' except smtplib.SMTPSenderRefused: print 'Sender refused' except smtplib.SMTPException as err: print 'err:',err
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
  • 相关阅读:
    别再低效筛选数据了!试试pandas query函数
    OpenStack常用命令
    C++primer 第二章 变量和基本类型
    算法通过村第十三关-术数|黄金笔记|数论问题
    『 Linux 』 进程间通信概述
    Java进阶教程(一)关键字
    02- 数据结构与算法 - 最长回文子串(动态规划/中心扩展算法/Manacher 算法)
    Cesium 展示——读取文件——加载 geojson 文件数据
    html 电子时钟
    图片标签的路径和属性标签
  • 原文地址:https://blog.csdn.net/longe20111104/article/details/133696208