• 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
  • 相关阅读:
    postgresql16配置主从
    redis的常用命令及使用特点
    异或最小生成树
    揭秘编码器与解码器语言模型
    Ant vue中表单验证(动态校验、部分校验)
    协同过滤电影推荐系统 计算机竞赛
    uboot启动流程-uboot内存分配
    曲线艺术编程 coding curves 第十四章 其它曲线(Miscellaneous Curves)
    网络安全(黑客)—2024自学
    贝叶斯定理,先验信念,似然,后验概率
  • 原文地址:https://blog.csdn.net/longe20111104/article/details/133696208