如何使用EntryIDCollection访问MS Outlook邮件?

时间:2013-05-14 05:13:25

标签: c# c#-4.0 outlook outlook-2010

我正在使用以下代码阅读Outlook邮件:

Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
int i = myInbox.Items.Count;
string strSubject = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[i]).Subject;
string senderEmailid = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[i]).SenderEmailAddress;
string ToEmailid = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[i]).To;
string CcEmailid = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[i]).CC;
string BccEmailid = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[i]).BCC;
string CreationTime = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[i]).CreationTime.ToString();

我也得到EntryIDCollection。如何使用EntryIDCollection而不是邮件计数(即我的代码中的i)来阅读邮件?

我正在使用MS Outlook 2010。

1 个答案:

答案 0 :(得分:1)

您可以使用Namespace.GetItemFromID