开发者

How decide whether a e-mail was newly sent, replied or forwarded?

开发者 https://www.devze.com 2023-02-04 00:59 出处:网络
I use Visual Studio 2010 to create an Outlook 20开发者_高级运维07 Addin. Now i want to know whether a e-mail was newly sent, replied or forwarded. Is there any property for this?

I use Visual Studio 2010 to create an Outlook 20开发者_高级运维07 Addin. Now i want to know whether a e-mail was newly sent, replied or forwarded. Is there any property for this?

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
    }
}


There are 3 Extended MAPI properties that deal with the message state for replied to/forwarded:

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

To get these values in Outlook 2007/2010, use the PropertyAccessor Object:

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

If it's a send in progress, the MailItem.Sent property will still be False.


MAPIFolder inbox = Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Items unreadItems = inbox.Items.Restrict("[UnRead] = true");

foreach (MailItem mail in unreadItems)
{
    // Do Stuff
}

This seems to work really well for me. I don't know that the mailitem itself would have this information. You could filter the olFolderSentMail folder instead.

  • http://office.microsoft.com/en-us/outlook-help/HV080801930.aspx
  • http://office.microsoft.com/en-us/outlook-help/HV080801921.aspx?CTT=5&origin=HV080801930
0

精彩评论

暂无评论...
验证码 换一张
取 消