如何通过 Python 从二级 outlook 电子邮件下载附件?
How download attachments from secondary outlook email by Python?
我需要从 outlook 下载附件,但我的 outlook 不需要。
我需要从辅助组地址获取它(例如 FiTeam@email.com
和 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?
中的收件箱下载附件
调用outlook.CreateRecipient("FiTeam@email.com")
,然后将返回的Recipient
对象传给outlook.GetSharedDefaultFolder()
要访问共享 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 下载附件,但我的 outlook 不需要。
我需要从辅助组地址获取它(例如 FiTeam@email.com
和 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?
调用outlook.CreateRecipient("FiTeam@email.com")
,然后将返回的Recipient
对象传给outlook.GetSharedDefaultFolder()
要访问共享 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')