简体   繁体   English

如何通过 Python 从辅助 Outlook 电子邮件中下载附件?

[英]How download attachments from secondary outlook email by Python?

I need download attachment from outlook, but not from my outlook.我需要从 Outlook 下载附件,但不需要从我的 Outlook 下载。

I need it from secondary group address (like FiTeam@email.com with pass = asdf).我需要来自次要组地址(如FiTeam@email.com with pass = asdf)。

Right now I have working script that downloading it from my own outlook address.现在我有工作脚本可以从我自己的 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')

How can I modify it to download the attachment from inbox in FiTeam@email.com?如何修改它以从FiTeam@email.com?收件箱中下载附件FiTeam@email.com?

To access the shared inbox try the following要访问共享inbox尝试以下操作

inbox = outlook.Folders["FiTeam@email.com"].Folders["Inbox"]

also you should fix ("D:\\DownloadingEmail\\\\replenishment") to ("D:\\\\DownloadingEmail\\\\replenishment")您还应该将("D:\\DownloadingEmail\\\\replenishment")修复为("D:\\\\DownloadingEmail\\\\replenishment")


SaveAsFile(os.path.join(path, str(attachment) should be SaveAsFile(os.path.join(path, str(attachment.FileName) SaveAsFile(os.path.join(path, str(attachment)应该是SaveAsFile(os.path.join(path, str(attachment.FileName)


message.Unread = False to message.UnRead message.Unread = Falsemessage.UnRead


see my example code below-请参阅下面的示例代码-

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.

相关问题 如何使用 Python 从 outlook 下载 email 附件 - How to download email attachments from outlook using Python 如何使用 python 3.4 下载 Outlook 电子邮件附件 - How to download outlook email attachments using python 3.4 如何从Outlook和Python中的辅助帐户发送电子邮件 - How to send Email from secondary Account in Outlook and Python Python从Outlook下载附件,而不循环通过每个电子邮件的每个附件 - Python download attachments from outlook, not looping thru each attachment per email 无法使用 Python 从 outlook 下载附件 || Python 3.10 - Unable to download attachments from outlook using Python || Python 3.10 如何从电子邮件下载附件并保留原始文件名? 使用Python / outlook - how to download attachments from e-mail and keep original filename? using Python/outlook 如何在python中从指定收件人收到新邮件后下载Outlook附件 - How to download Outlook attachments after receiving new mail from specified receiver in python 使用 Python 从 Outlook 365 中提取电子邮件附件 - Extracting Email Attachments from Outlook 365 using Python Python:保存未读的所有附件 Outlook email - Python: Save all attachments from unread Outlook email 如何在Python和Outlook中使用for循环在电子邮件中保存所有附件? - How to save all attachments in email using for loop in Python and Outlook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM