简体   繁体   English

如何检索邮件项的Outlook文件夹(Outlook.MailItem)?

[英]How to retrieve the Outlook folder of a mail item (Outlook.MailItem)?

I am getting my default inbox folder via inboxFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox 我通过inboxFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox获取我的默认收件箱文件夹

Elsewhere in my code, I begin doing a foreach loop to extract specific information I want from these MailItems 在我的代码的其他地方,我开始做一个foreach循环,从这些MailItems中提取我想要的特定信息

foreach (var item in this.inboxFolder.Items)
{
   Outlook.MailItem mailItem = (Outlook.MailItem)item;
   //.... doing stuff here
   string SenderEmail = mailItem.SenderEmailAddress;
   string SenderName = mailItem.SenderName;
   string FolderLocation = mailItem.???;  //how to retrieve folder location?
   //.... more stuff here
}

For example: A user may have created a subfolder called 'Test' shown below. 例如:用户可能已经创建了一个名为“Test”的子文件夹,如下所示。

Outlook-2010中用户创建的子文件夹的图像

Thank you for the pointer guys. 谢谢指针家伙。 However I was having some trouble implementing the same initially. 但是我最初在执行相同操作时遇到了一些麻烦。 Here is how I solved it, just in case if some one faces the same issue. 以下是我如何解决它,以防万一有人面临同样的问题。

Outlook.MAPIFolder parentFolder = mailItemToDelete.Parent as Outlook.MAPIFolder;
string FolderLocation = parentFolder.FolderPath;

The Parent object is dynamic and hence was causing issue. Parent对象是动态的,因此导致问题。

Do you mean folder path? 你的意思是文件夹路径? Use MAPIFolder.FullFolderPath. 使用MAPIFolder.FullFolderPath。 Or MAPIFoldert.Name if you only need the name. 如果您只需要名称,请使用MAPIFoldert.Name。

Also keep in mind that the value will be the same for all items in the folder, so there is no reason to evaluate it on each step of the loop. 另外请记住,文件夹中的所有项目的值都是相同的,因此没有理由在循环的每个步骤中对其进行评估。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM