[英]How download attachments from secondary outlook email by Python?
我需要從 Outlook 下載附件,但不需要從我的 Outlook 下載。
我需要來自次要組地址(如FiTeam@email.com
with pass = asdf)。
現在我有工作腳本可以從我自己的 Outlook 地址下載它。
import os
path = os.path.expanduser("D:\DownloadingEmail\\replenishment")
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
def saveattachemnts(subject):
for message in messages:
if message.Subject.startswith(subject):
# 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
continue
saveattachemnts('Replenishment')
如何修改它以從FiTeam@email.com?
收件箱中下載附件FiTeam@email.com?
要訪問共享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')
調用outlook.CreateRecipient("FiTeam@email.com")
,然后將返回的Recipient
對象傳遞給outlook.GetSharedDefaultFolder()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.