首页 > 解决方案 > Python:如何仅从 Outlook 中获取电子邮件中的最新消息

问题描述

我只想在使用 Python 3 从 Outlook 发送的电子邮件中提取最新消息,而无需通过 Re,Fw 提取。

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
print(inbox.Items[len(inbox.Items)-1].body)

标签: pythonoutlookwin32com

解决方案


使用“Item.GetLast()”

例子:

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder = outlook.Folders.Item("Your Mailbox")
inbox = folder.Folders.Item("Inbox")
msg = inbox.Items
msgs = msg.GetLast()
print(msgs)

希望这可以帮助。


推荐阅读