如何在Python的Outlook收件箱中访问子文件夹 [英] How to access a subfolder in Outlook inbox in Python

查看:876
本文介绍了如何在Python的Outlook收件箱中访问子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Outlook中创建了一条规则,可以将所有传入邮件从特定发件人移至收件箱"中的子文件夹.就像-

I have created a rule in Outlook to move all incoming messages from a particular sender to a subfolder in my Inbox.Like -

Inbox
- Subfolder

我写了一段代码

import win32com.client

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

inbox = outlook.GetDefaultFolder(6) #6 = Inbox (without mails from the subfolder)
messages = inbox.Items
message = messages.GetLast()
body_content = message.body 
print body_content #Sometimes has parsing error due to different encoding format

我怎么

1)阅读收件箱中此特定文件夹中的邮件

1) Read the mails in this particular folder inside Inbox

2)注意像UnicodeEncodeError这样的错误:'charmap'编解码器无法编码-字符映射到

2) Take care of error like UnicodeEncodeError: 'charmap' codec can't encode - character maps to

print (u'\2109')也会发出此错误.

推荐答案

outlook.GetDefaultFolder(6)默认为收件箱"位置.您需要遍历其中的文件夹列表,因此请尝试

outlook.GetDefaultFolder(6) is "Inbox" position by default. You need to traverse the list of folders in it, so try this

inbox = outlook.GetDefaultFolder(6).Folders.Item("Your_Folder_Name")

这篇关于如何在Python的Outlook收件箱中访问子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆