使用 win32com 和/或 active_directory,如何按名称访问电子邮件文件夹?
在带有 Outlook 2007 的 python 中,使用 win32com 和/或 active_directory,如何获取对子文件夹的引用,以便我可以将 MailItem 移动到该子文件夹?
我的收件箱结构如下:
Inbox | +-- test | `-- todo
我可以访问收件箱文件夹,如下所示:
import win32com.client
import active_directory
session = win32com.client.gencache.EnsureDispatch("MAPI.session")
win32com.client.gencache.EnsureDispatch("Outlook.Application")
outlook = win32com.client.Dispatch("Outlook.Application")
mapi = outlook.GetNamespace('MAPI')
inbox = mapi.GetDefaultFolder(win32com.client.constants.olFolderInbox)
print '\n'.join(dir(inbox))
但是当我尝试获取子目录 test
per Microsoft 的示例 inbox
对象没有 Folders
接口或任何获取子目录的方式。
如何获取指向 test
子目录的 Folder
对象?
In python w/ Outlook 2007, using win32com and/or active_directory, how can I get a reference to a sub-folder so that I may move a MailItem to this sub-folder?
I have an inbox structure like:
Inbox
|
+-- test
|
`-- todo
I can access the inbox folder like:
import win32com.client
import active_directory
session = win32com.client.gencache.EnsureDispatch("MAPI.session")
win32com.client.gencache.EnsureDispatch("Outlook.Application")
outlook = win32com.client.Dispatch("Outlook.Application")
mapi = outlook.GetNamespace('MAPI')
inbox = mapi.GetDefaultFolder(win32com.client.constants.olFolderInbox)
print '\n'.join(dir(inbox))
But when I try to get subdirectory test
per Microsoft's example the inbox
object doesn't have the Folders
interface or any way to get a subdirectory.
How can I get a Folder
object which points to test
subdir?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我意识到这是一个老问题,但我最近一直在使用 win32com 包,发现文档至少可以说很麻烦......我希望有一天有人可以拯救我在尝试理解 MSDN 时所经历的混乱解释
下面是一个 Python 脚本示例,用于遍历 Outlook 文件夹,访问我想要访问的电子邮件。
免责声明
我移动了代码并取出了一些敏感信息,因此如果您尝试复制并粘贴它并让它运行,祝您好运。
PS 希望这不会弊大于利。
I realize this is an old question but I've been using the win32com package recently and found the documentation troublesome to say the least...My hope is that someone, someday can be saved the turmoil I experienced trying to wrap my head around MSDN's explanation
Here's and example of a python script to traverse through Outlook folders, accessing e-mails where I please.
Disclaimer
I shifted around the code and took out some sensitive info so if you're trying to copy and paste it and have it run, good luck.
PS Hope this doesn't do more harm than good.
对我有用的东西是迭代文件夹名称。 (当我发布这个问题时,我无法弄清楚文件夹名称)。
Something that did work for me was iterating over the folder names. ( When I posted this question, I couldn't figure out the folder names ).
这对我来说可以将邮件项目移动到“test”子目录中(通过删除 gencache 的东西来简化):
This works for me to move a mail item into a "test" subdirectory (simplified by getting rid of gencache stuff):
因此,下面的代码将抓取 SOURCE 文件夹中的“Last”项目,然后将其移动到 DEST 文件夹。抱歉,代码有点生硬,我删除了所有附加功能,例如阅读和保存邮件。
So the below code will grab the "Last" item in the SOURCE folder and then move it to DEST folder. Sorry the code is a bit blunt I removed all additional features such as reading and saving the mail.