1 year ago

#359012

test-img

INGl0R1AM0R1

SaveasFile Outlook mail function giving me error giving : acess denied you dont have permission for this operation

So what am i trying to do is basically, save an attachment. That is on a specific email. With a specific date on it, but when i try to execute the SaveasFile method. I get an error. (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'Not possible to save attachment. You dont have the permission to execute this operation.', None, 0, -2147024891), None)

My base code is as follows.

path_zip = "../Query/Full_prod"  #localizacao onde fica a file zipada

outlook = win32com.client.Dispatch('outlook.application')# Abre o outlook

mapi = outlook.GetNamespace("MAPI") #Call do outlook

root_folder = mapi.Folders.Item(1) # Folder inicial do seu outlook

subfolder = root_folder.Folders['Eventtracks bot prod'] # Subfolder do local arquivado

messages = subfolder.Items


def SalvaAnexo(): # Retorna os anexos que nao estao sendo salvos.
    created_files = os.listdir(f'{path_zip}/Marco') #Mes desejado
    created_files = [i[3:5] for i in created_files] # Dias ja criados
    for message in messages: 
        if "2022-03" in message.Subject: # Filtro para diminuir tamanho do loop
                attachments = message.Attachments
                attachment = attachments.Item(1) #Pegando o attachment
                dias_email = str(message.Subject.split("-")[-1]) #Dia dos attachment
                if dias_email not in created_files:
                    print(dias_email)
                    attachment.SaveasFile(r'E:\csms\Query\Full_prod')

Is worth noting that before hand i used this function on my C: drive and this little function worked perfectly. Would apreciate some help.

python

win32com

0 Answers

Your Answer

Accepted video resources