【问题标题】:How decide whether a e-mail was newly sent, replied or forwarded?如何确定电子邮件是新发送、回复还是转发?
【发布时间】:2011-06-07 20:37:42
【问题描述】:

我使用 Visual Studio 2010 创建 Outlook 2007 插件。现在我想知道一封电子邮件是否是新发送、回复或转发的。这个有什么属性吗?

using Outlook = Microsoft.Office.Interop.Outlook;

namespace _Outlook2k7_Add_In
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        void Application_ItemSend(object Item, ref bool Cancel)
        {
            Outlook.MailItem mail = Item as Outlook.MailItem;

            if (mail == null)
                return;

            // Magic?
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
        }

        #endregion
    }
}

【问题讨论】:

    标签: c# outlook-addin outlook-2007


    【解决方案1】:

    有 3 个扩展 MAPI 属性处理回复/转发的消息状态:

    PR_ICON_INDEX (0x10800003) PR_LAST_VERB_EXECUTED (0x10810003) PR_LAST_VERB_EXECUTION_TIME (0x10820040)

    要在 Outlook 2007/2010 中获取这些值,请使用 PropertyAccessor 对象:

    http://msdn.microsoft.com/en-us/library/bb176395(office.12).aspx

    如果正在发送,MailItem.Sent 属性仍将为 False。

    【讨论】:

    • 我不是 100% 确定,但我相信 MAPI 属性仅在使用 Exchange 服务器时设置,而不是在 POP/IMAP/SMTP 情况下设置。 OP 没有说明他们正在使用哪个,因此这可能会或可能不会影响他们。
    • 否,所有 Outlook 项目都使用 MAPI 属性,与应用商店无关。有特定于 Exchange 的属性,但有问题的是标准属性。
    【解决方案2】:
    MAPIFolder inbox = Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
    Items unreadItems = inbox.Items.Restrict("[UnRead] = true");
    
    foreach (MailItem mail in unreadItems)
    {
        // Do Stuff
    }
    

    这对我来说似乎非常有效。我不知道 mailitem 本身会有这些信息。您可以改为过滤 olFolderSentMail 文件夹。

    【讨论】:

      猜你喜欢
      • 2015-12-19
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 2018-11-21
      • 2013-11-06
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      相关资源
      最近更新 更多