2013-05-30 268 views
1

我想統計收到的郵件數量,在主題行中有單詞說'xyz'。但我不希望它重複計數,我的意思是如果我收到帶有主題的郵件'xyz',我回復它,包括我自己我希望被算作1而不是2。在outlook中可能嗎?計算Outlook文件夾中的電子郵件數量

+0

哪個版本的Outlook? – SliverNinja

回答

0

是啊,這可能definetly,你沒有指定你使用的techno,但使用互操作的樣本代碼可能是:

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; 
} 

希望它可以幫助別人,

相關問題