在共享文件夹中阅读Outlook电子邮件-Python

时间:2019-11-14 13:11:12

标签: python outlook win32com

我一直在使用以下代码访问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)

有什么方法可以从共享邮箱中搜索电子邮件?

谢谢

1 个答案:

答案 0 :(得分:1)

尝试一下:

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