Python显示COM对象

2024-09-30 05:17:31 发布

您现在位置:Python中文网/ 问答频道 /正文

import win32com.client
outlook=win32com.clent.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox=outlook.GetDefaultFolder(6)
messages=inbox.Items
message.messages.GetLast()
body_content=message.Body
print(body_content)

这将打印收件箱中的电子邮件正文。我想做的是揭示这段代码的每个阶段都发生了什么,这样我就可以更好地理解它,但是当我试图打印收件箱时,我收到的消息是:

^{pr2}$

我该如何揭示这一点,这样我就可以开始了解我在做什么。在

我也在寻找一个地方,如果有人可以分享的话,有一个关于使用python与msoutlook交互的清晰文档的地方。在


Tags: importclientmessageapplication地方bodycontentwin32com
2条回答

我还不能发表评论,但我想补充一下本的回答(在类似的情况下,这对我帮助很大)

我想要一种从Outlook的多个PST文件/帐户中获取电子邮件的方法

import win32com.client

outlook_object = win32com.client.Dispatch("Outlook.Application")

namespace = outlook_object.GetNamespace("MAPI")

# collection of accounts
accounts = namespace.Folders

# number of outlook accounts
accounts_count = accounts.Count

# .Item(1) not .Item(0) because counting starts at 1
account1 = accounts.Item(1)

# collection of folders for account1
account_folders = account1.Folders
# number of folders under outlook account
account_folders_count = account_folders.Count

# print account1 folder names
for folder in range(account_folders_count):
    # must be +1 because .Folder(0) and .Item(0) do not work
    print str(folder+1)+":", account_folders.Item(folder+1)

有一种模式可以使用Folders.CountFolders.Item(1)来获取消息。希望这能对某些人有所帮助,因为我花了几个小时在谷歌上搜索到这一点。在

在这里试试:

在outlook对象模型中,大多数对象都有一个Class属性,它返回一个OlObjectType类型的枚举,说明它是什么类型的对象。outlook(实际上也是msoffice)对象的其他属性是Parent和{}。在

如果您真的愿意,应该很容易生成一个函数describe_outlook_object,该函数返回一个包含有用信息的字符串。当然,你得自己写。在

或者,如果您只想探索对象模型,您可以做得比在Outlook中按Alt+F11并使用visualbasic做得更好。(必须启用宏。)

相关问题 更多 >

    热门问题