Для доступа к общему inbox
попробуйте следующее
inbox = outlook.Folders["FiTeam@email.com"].Folders["Inbox"]
, также вы должны исправить ("D:\DownloadingEmail\\replenishment")
на ("D:\\DownloadingEmail\\replenishment")
SaveAsFile(os.path.join(path, str(attachment)
должно быть SaveAsFile(os.path.join(path, str(attachment.FileName)
message.Unread = False
до message.UnRead
см. Мой пример кода ниже-
import os
import win32com.client
path = os.path.expanduser("D:\\DownloadingEmail\\replenishment")
print(path)
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.Folders["FiTeam@email.com"].Folders["Inbox"]
messages = inbox.Items
def save_attachments(subject):
for message in messages:
if message.Subject.startswith(subject):
for attachment in message.Attachments:
attachment.SaveAsFile(os.path.join(path, str(attachment.FileName)))
if message.UnRead:
message.UnRead = False
continue
save_attachments('Replenishment')