如何在 Python 中访问 Outlook 收件箱中的子文件夹

Pra*_*dra 5 python outlook pywin32

我在 Outlook 中创建了一个规则,将所有传入邮件从特定发件人移动到我的收件箱中的子文件夹中。Like -

Inbox
- Subfolder
Run Code Online (Sandbox Code Playgroud)

我写了一段代码

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
Run Code Online (Sandbox Code Playgroud)

我怎样才能

1)阅读收件箱内这个特定文件夹中的邮件

2) 处理像 UnicodeEncodeError: 'charmap' codec can't encode - character maps to

print (u'\2109') 也发出这个错误。

Jea*_*bre 2

u'\2109'看起来很像 UTF-8 编码。

这样print(body_content.encode("utf-8"))就可以解决问题了。