1

I use a batch file to run to open and close Outlook. After opening, how to open an email, and click on the download button using python 'import win32com.client' library? any suggestions?

report download

I was able to download the attachment from the email, however they stopped sending the file as an attachment, but now the download link instead..

import datetime
import os
import win32com.client 
from pathlib import Path
home = str(Path.home())path = 'where to download'
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")  #opens outlookinbox = outlook.GetDefaultFolder(6)messages = inbox.Items
def saveattachemnts(subject):for message in messages:if message.Subject == subject and message.Unread:#if message.Unread:  #I usually use this because the subject line contains time and it varies over time. So I just use unread
        # body_content = message.body
        attachments = message.Attachments
        attachment = attachments.Item(1)
        for attachment in message.Attachments:
            attachment.SaveAsFile(os.path.join(path, str(attachment)))
            if message.Subject == subject and message.Unread:
                message.Unread = False
            break                
saveattachemnts('Scheduled Report BI Report - All NPIs - Active and Net New NPIs (Do Not Edit): You have received a new report')

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.