确定所选电子邮件是来自收件箱还是已发送项目 [英] Determine if the selected email is from inbox or sent items

查看:306
本文介绍了确定所选电子邮件是来自收件箱还是已发送项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程的 Outlook插件并需要确定一个选择的电子邮件是否来自收件箱已发项目,这样我可以标记与文件夹中的邮件=收件箱或已发送当我将它保存在我的数据库。

I am programming an Outlook Add-in and need to determine whether a selected email is from Inbox or Sent Items so that I can tag the email with folder="Inbox" or "Sent" when I save it in my database.

我知道我可以在文件夹名称比较收件箱或已发送邮件,并确定该文件夹,但是,我怎么确定时选定的电子邮件是坐在之一子文件夹在收件箱中。是否有一个 FolderType 属性,查看所选邮件的文件夹是否为收件箱发送相似的识别项目类型与 OlItemType 的)?

I understand that I can compare the folder name to Inbox or Sent Items and determine the folder, however, how do I determine when the email selected is sitting in one of the sub-folders in the inbox. Is there a FolderType property to check whether the selected email's folder is inbox or sent (similar to identifying an item type with OlItemType)?

推荐答案

您需要看 MailItem.Parent 并把它转换为一个 Outlook.Folder 。一旦你的文件夹,您可以通过的 Folder.Name 。如果你想确定所选项目是否是收件箱的子文件夹,您将需要递归调用的树,直到为空找了根父文件夹。

You need to look at the MailItem.Parent and cast it to a Outlook.Folder. Once you have the Folder, you can access the display name via Folder.Name. If you want to determine whether the selected item is a subfolder of Inbox, you would need to recursively call up the Parent tree until Parent is null to find the root parent folder.

Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
Outlook.MailItem mailItem = explorer.Selection.OfType<Outlook.MailItem>().First();
Outlook.Folder parentFolder = mailItem.Parent as Outlook.Folder;
if (parentFolder.Parent == null) // we are at the root
{
  string folderName = parentFolder.Name;
}
else
  // .. recurse up the parent tree casting parentFolder.Parent as Outlook.Folder...

您应该明显增加的错误处理的和的对象处理的这个示例代码。

You should obviously add error handling and object disposal to this sample code.

这篇关于确定所选电子邮件是来自收件箱还是已发送项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆