
Мне удалось загрузить вложение из электронного письма, однако они перестали присылать файл как вложение, а теперь вместо него появилась ссылка для скачивания..
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')
Подробнее здесь: https://stackoverflow.com/questions/788 ... oad-button