【问题标题】:Reading Outlook Emails in Shared Folder - Python在共享文件夹中阅读 Outlook 电子邮件 - Python
【发布时间】:2019-11-14 13:11:12
【问题描述】:

我一直在使用以下代码访问 Outlook 中的公用文件夹:

import win32com.client
import datetime


outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(18).Folders.Item("xxxxx")
messages = inbox.Items
date = datetime.date.today()


subject = "xxxxxxx"

for message in messages:
    if subject in message.subject and date in message.senton.date():
     print(message.senton.time())

但是,我们的 Outlook 已从 Exchange 服务器移至云端,公用文件夹已更改为共享文件夹(我认为?)。上面的代码不再有效,我收到以下错误:

pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The attempted operation failed.  An object could not be found.', None, 0, -2147221233), None)

有没有办法从共享邮箱中搜索邮件?

谢谢

【问题讨论】:

    标签: python outlook win32com


    【解决方案1】:

    试试这个:

    inbox = outlook.Folders("Name of Shared Folder").Folders.Item("xxxxx")

    【讨论】:

    • 太棒了!这似乎奏效了,不过我还有一个问题。我似乎无法使用以前在旧文件夹中使用的代码从电子邮件中下载附件。我已经用下载附件的代码更新了我的问题。你知道怎么做吗?
    • 好吧,没关系,我想我会发布一个单独的问题。再次感谢您的帮助!
    • 你可以使用attachments = message.Attachments然后测试它是否有效,打印附件的名称:for i in range(attachments.Count): attachment = attachments.Item(i+1) print(attachment)
    • 好吧,例如,您知道如何指定仅下载 excel 附件吗?并忽略 pdf 等?
    • 我建议对字符串使用find() 函数并查找“.xlsx”或“.pdf”。祝你好运!
    猜你喜欢
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 2020-03-11
    相关资源
    最近更新 更多