简体   繁体   中英

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

I use Visual Studio 2010 to create an Outlook 2007 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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