C# 如何在c中阅读outlook中包含特定主题的所有邮件#
在我看来,我有很多电子邮件,其中一些主题是相同的<代码>程序中的文档 我想要的是我必须找到所有的。但在我的代码中,它只能找到一个。我如何修复它C# 如何在c中阅读outlook中包含特定主题的所有邮件#,c#,outlook,C#,Outlook,在我看来,我有很多电子邮件,其中一些主题是相同的程序中的文档 我想要的是我必须找到所有的。但在我的代码中,它只能找到一个。我如何修复它 try { Microsoft.Office.Interop.Outlook.Application MyApp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace MailNS = MyA
try
{
Microsoft.Office.Interop.Outlook.Application MyApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace MailNS = MyApp.GetNamespace("mapi");
Microsoft.Office.Interop.Outlook.MAPIFolder MyInbox = null;
MyInbox = MailNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
Microsoft.Office.Interop.Outlook._MailItem InboxMailItem = null;
Microsoft.Office.Interop.Outlook.Items oItems = MyInbox.Items;
string Query = "[Subject] = 'document from program'";
InboxMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oItems.Find(Query);
Console.WriteLine("Subject: {0}", InboxMailItem.Subject);
Console.WriteLine("Sendername: {0}", InboxMailItem.SenderName);
Console.WriteLine("Body: {0}", InboxMailItem.Body);
}
catch (Exception ex)
{
MessageBox.Show("There is no mail with that subject");
}
抱歉,我的英文版看起来Find()返回“满足给定筛选器的Outlook项目对象”
注意“an”是单数,所以是第一个匹配项
从这里开始,我认为您需要迭代调用FindNext()来获取所有项目
> FindNext() After the Find(String) method runs, this method finds and
> returns the next Outlook item in the specified collection.