2010-08-22 68 views
9

任何人都可以告訴我如何使用imap或其他方法從Gmail中獲取我的收件箱中未讀項目的數量並將其顯示在C#WinForms中的標籤中?使用IMAP計算gmail中的電子郵件數

我試着用原子飼料,但絕不能拿它

這是我想要的樣子,如果它可以幫助:

Inbox(1)

+0

請刪除問題的答案並將其作爲實際答案發布。謝謝! – Timwi 2010-08-23 01:17:54

回答

6

你可能想找到的所有郵件UNSEEN標誌設置。

Imap imap = new Imap(); 
/* connect, login, etc. */ 
imap.Connect(...); 
/* fill login and select folder code */ 

List<long> unseenList = imap.SearchFlag(Flag.Unseen); 

// now you can get the count from unseeList 
int unread = unseenList.Count; 
+0

你可以elaoborate多一點IM完全新到progrsmming – Shane121 2010-08-22 01:15:53

+1

@user請參閱編輯答案 – quantumSoup 2010-08-22 01:21:32

+0

感謝您的幫助很好,所以我將如何顯示dis在標籤 – Shane121 2010-08-22 02:07:35

9

解決

這裏是我與ImapX組件使用的代碼:

ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true); 
     bool result = false; 

     result = client.Connection(); 
     if (result) 
      MessageBox.Show("Connection Established"); 

     result = client.LogIn(textBox1.Text, textBox2.Text); 
     if (result) 
     { 
      MessageBox.Show("Logged in"); 
      ImapX.FolderCollection folders = client.Folders; 
      ImapX.MessageCollection messages = client.Folders["INBOX"].Search("UNSEEN", true); //true - means all message parts will be received from server 

      int unread = messages.Count; 
      string unseen = unread.ToString(); 
      button1.Text = unseen; 
     } 

我不得不整型隱蔽爲字符串,並示出了在字符串(看不見)按鈕。感謝quantumSoup將我指向正確的方向

+3

如果上述Url不起作用,可以嘗試從http://imapx.codeplex.com使用新版本 – Evereq 2013-02-12 15:49:31

相關問題