python - 使用win32com按Outlook中的对话线程对邮件进行分类/分组?
问题描述
有没有办法通过那里循环所有邮件,,,ConversationID
并根据相同的id号对它们进行分组EntryID
,以便它们可以像outlooks功能一样打印出来。GetConversation
ConversationIndex
find related
outlook.GetItemFromID(id)
仅适用于EntryID
所有邮件独有的作品。
我试图遍历所有邮件并找到相应的 ID 号,并匹配是否有任何具有相同 ID 号的邮件。但是所有的 id 似乎都是独一无二的。
解决方案
您可以使用该类的GetConversation方法,该方法MailItem
获取一个Conversation对象,该对象表示该项目所属的对话。
如果项目不存在对话,则GetConversation 返回Null
(在 Visual Basic 中)。Nothing
在以下情况下,项目不存在对话:
- 该项目尚未保存。可以通过编程、用户操作或自动保存来保存项目。
- 对于可以发送的项目(例如,邮件项目、约会项目或联系人项目),该项目尚未发送。
- 已通过 Windows 注册表禁用对话。
- 商店不支持
Conversation
视图(例如,Outlook 正在经典联机模式下针对早于 Microsoft Exchange Server 2010 的 Microsoft Exchange 版本运行)。使用对象的IsConversationEnabled属性Store
来确定商店是否支持对话视图。
下面的 C# 示例代码(抱歉,我不熟悉 python,但 Outlook 对象模型对所有编程语言都是通用的)假设资源管理器窗口中的选定项目是邮件项目。该代码示例获取与所选邮件项关联的对话,并枚举该对话中的每个项目,显示项目的主题。
void DemoConversation()
{
object selectedItem =
Application.ActiveExplorer().Selection[1];
// This example uses only
// MailItem. Other item types such as
// MeetingItem and PostItem can participate
// in the conversation.
if (selectedItem is Outlook.MailItem)
{
// Cast selectedItem to MailItem.
Outlook.MailItem mailItem =
selectedItem as Outlook.MailItem;
// Determine the store of the mail item.
Outlook.Folder folder = mailItem.Parent
as Outlook.Folder;
Outlook.Store store = folder.Store;
if (store.IsConversationEnabled == true)
{
// Obtain a Conversation object.
Outlook.Conversation conv =
mailItem.GetConversation();
// Check for null Conversation.
if (conv != null)
{
// Obtain Table that contains rows
// for each item in the conversation.
Outlook.Table table = conv.GetTable();
Debug.WriteLine("Conversation Items Count: " +
table.GetRowCount().ToString());
Debug.WriteLine("Conversation Items from Table:");
while (!table.EndOfTable)
{
Outlook.Row nextRow = table.GetNextRow();
Debug.WriteLine(nextRow["Subject"]
+ " Modified: "
+ nextRow["LastModificationTime"]);
}
Debug.WriteLine("Conversation Items from Root:");
// Obtain root items and enumerate the conversation.
Outlook.SimpleItems simpleItems
= conv.GetRootItems();
foreach (object item in simpleItems)
{
// In this example, enumerate only MailItem type.
// Other types such as PostItem or MeetingItem
// can appear in the conversation.
if (item is Outlook.MailItem)
{
Outlook.MailItem mail = item
as Outlook.MailItem;
Outlook.Folder inFolder =
mail.Parent as Outlook.Folder;
string msg = mail.Subject
+ " in folder " + inFolder.Name;
Debug.WriteLine(msg);
}
// Call EnumerateConversation
// to access child nodes of root items.
EnumerateConversation(item, conv);
}
}
}
}
}
void EnumerateConversation(object item,
Outlook.Conversation conversation)
{
Outlook.SimpleItems items =
conversation.GetChildren(item);
if (items.Count > 0)
{
foreach (object myItem in items)
{
// In this example, enumerate only MailItem type.
// Other types such as PostItem or MeetingItem
// can appear in the conversation.
if (myItem is Outlook.MailItem)
{
Outlook.MailItem mailItem =
myItem as Outlook.MailItem;
Outlook.Folder inFolder =
mailItem.Parent as Outlook.Folder;
string msg = mailItem.Subject
+ " in folder " + inFolder.Name;
Debug.WriteLine(msg);
}
// Continue recursion.
EnumerateConversation(myItem, conversation);
}
}
}
推荐阅读
- r - R Studio“过滤器”功能问题。过滤掉不包含特定值的项目
- javascript - JavaScript - 如何防止多个运算符输入?(加法和减法)
- java - 从 JAVA 的 Imgproc 类中删除 FONT_HERSHEY_SIMPLEX
- python - MySQL 错误:无法连接。通过 for 循环添加数据时设置无效
- python - 如何制作不下载系统音乐的discord.py音乐?
- flutter - Flutter 类型“String”不是“FutureOr”类型的子类型
' , 无键响应 Json - mysql - 如何在 octoberCMS 查询中组合多个 and or 条件?
- php - httpd.conf 会覆盖 php.ini 吗?
- r - R tmap:在 tmap_mode("view") 中绘制的多边形,但只有第一个观察值 ("plot")
- r - 如何对R中的“系列”向量进行向量化操作