python - 如何使用Python从辅助Outlook电子邮件中下载附件?

标签 python outlook win32com

我需要从 Outlook 下载附件,但不需要从我的 Outlook 下载附件。

我需要从辅助群组地址(例如带有 pass = asdf 的 FiTeam@email.com)获取它。

现在我有工作脚本,可以从我自己的 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 的收件箱下载附件?

最佳答案

访问共享 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 = Falsemessage.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')

关于python - 如何使用Python从辅助Outlook电子邮件中下载附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60038283/

相关文章:

python - 如何将 Pandas 中的变量指定为序数/分类?

python - 还有比这更好的混合 websocket 接收和发送调用的方法吗?

python - 融化多索引 pandas 保留 2 列

asp.net-mvc - Outlook 2010 忽略我的应用程序生成的 Web 日历 (ICS) 的 VALARM

html - outlook html 时事通讯中的空白

email - 如何使用 Outlook 的 SMTP 服务器发送电子邮件?

python - 使用来自 win32com 的数据向 Excel 提供命名冲突 (_FilterDatabase)

python - 对以小写字母或大写字母开头的带重音符号的名称进行排序

python - 使用 Python 的 `Nothing` 传递变量 `win32com`

Python读取我的outlook邮箱并解析邮件