我想计算我收到的主题行中包含“xyz”字样的邮件数量。但我不希望它计算重复,我的意思是如果我收到一封主题为“xyz”的邮件并且我回复它,包括我自己我希望将其计为 1 而不是 2。在 Outlook 中可能吗?
问问题
1187 次
1 回答
0
是的,这绝对是可能的,您没有指定要使用的技术,但使用互操作的示例代码可能是:
var outlookApp = new Outlook.Application();
var mapi = outlookApp.GetNamespace("MAPI")
var root = mapi.GetDefaultFolder(OlDefaultfolders.olFolderInbox)
var folders = root.Folders;
int count = 0;
for(int i = folders.Count; i >= 1; i--)
{
var folder = folders[i];
count += GetCount(folder, 0);
Marshal.ReleaseComObject(folder);
}
Marshal.ReleaseComObject(folders);
//... function
private int GetCount(MAPIFolder folder, int count)
{
var folderItems = folder.Items;
if(folderItems != null && folderItems.Count >= 1)
{
for(int i = folderItems.Count; i >= 1; i--)
{
//Check item.Subject for string logic
count++;
//Add item in collection variable to check duplicates,
//generate an id with subject + creationtime for tracking?
}
}
if(folder.Folders != null && folder.Folders >= 1)
{
var subFolders = folder.Folders;
for(int i = subfolders.Count; i >= 1; i--)
{
var subFolder = subFolders[i]
count += GetCount(subFolder, count);
Marshal.ReleaseComObject(subfolder);
}
}
Marshal.ReleaseComObject(folderItems);
return count;
}
希望它可以帮助某人,
于 2013-08-22T19:13:43.023 回答