'Python - win32com write email - online archive

With this code :

import win32com.client
import pandas as pd
import os
from datetime import datetime, timedelta
import xlrd
import numpy as np

#######################################################################################################
######################################### UTILITY METH ################################################
#######################################################################################################
def lastOne(mess,veeamObj,first):
    for i in range(1, len(messages)):
        mess = messages[len(messages) - i]
        if ((mess.body).find(veeamObj) != -1 and (mess.body).find(first) != -1 ):
            return mess
def sendMsg():

    outlook = win32com.client.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = '[email protected]'
    mail.Subject = 'Backup email'
    mail.Body = 'Backup'
    mail.Attachments.Add('C:/Users/ala/PycharmProjects/outlook/MonitoringBackup.xlsx')
    mail.send

#######################################################################################################
############################################ MAIN #####################################################
#######################################################################################################

# Ouverture des fichiers outlook
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
accounts = outlook.Folders
print("Account : " + str(accounts[5]))
print("file : " + str(accounts[5].folders[9]))
messages = accounts[5].folders[9].Items

#lecture et création de de PD
customerList = pd.read_excel('bugs.xlsx', index_col=0)
final = pd.DataFrame( columns=["Client", "veeamObj" ,"veeam", "date", "statut"])
pd.options.display.max_columns = None
pd.options.display.max_rows = None


for i in range(0,len(customerList)):
    print("Pour le client : " + customerList.index[i])
    trans = customerList.iloc[i]
    email = trans[0]
    email=email
    veeamObj = trans[1]
    args = int(trans[2])
    first = trans[3]

    mess = messages
    NbMsg = len(mess)

    #tri par date et par adresse
    received_dt = datetime.now() - timedelta(days=35846)
    received_dt = received_dt.strftime('%m/%d/%Y %H:%M %p')
    mess = mess.Restrict("[ReceivedTime] >= '" + received_dt + "'")
    mess = mess.Restrict("[SenderEmailAddress] = " + "'" + email + "'")
    mess = lastOne(mess,veeamObj,first)

    #checking all the veeam instance
    for j in range(3, args+2):

        ind = (mess.body).find(trans[j])
        letter = mess.body[ind+len(trans[j])+1]

        if (letter == 'S'):
            print(customerList.index[i] + " - " + trans[j] + " - " + str(mess.ReceivedTime) + " - ok")
            add = pd.DataFrame([[" ", veeamObj,str(trans[j]), str(mess.ReceivedTime), "OK"]], columns=["Client", "veeam", "date", "statut"])
            final = pd.concat([final, add])
        elif (letter == 'W'):
            print(customerList.index[i] + " - " + trans[j] + " - " + str(mess.ReceivedTime) + " - Warning")
            add = pd.DataFrame([[" ", veeamObj, str(trans[j]), str(mess.ReceivedTime), "Warning"]], columns=["Client", "veeam", "date", "statut"])
            final = pd.concat([final, add])
        else:
            print(customerList.index[i] + " - " + trans[j] + " - " + str(mess.ReceivedTime) + " - ERROR")
            add = pd.DataFrame([[" ", veeamObj, str(trans[j]), str(mess.ReceivedTime), "ERROR"]], columns=["Client", "veeam", "date", "statut"])

            final = pd.concat([final, add])
print("##############################################################################")


final.to_excel('C:/Users/ala/PycharmProjects/outlook/MonitoringBackup.xlsx', sheet_name='sheet1', index=False)

Yesterday when I launch my code all was good in minus than 1 minute stop with good the good output. But since today the code take a while to finish, and I've this message that appear every time the code read message enter image description here

I don't have idea of where to look for to resolved my issue



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source