我想要计算收到的邮件数量,在主题行中有'xyz'字样。但我不想让它重复计算,我的意思是如果我收到主题'xyz'的邮件,我会回复它包括我自己,我希望它被计为1而不是2.在展望中是否可能?
答案 0 :(得分: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;
}
希望它有所帮助,