Polzi
Polzi

Reputation: 77

Detect if current Outlook window is a Forward Email?

I have an Outlook plugin. I have an inspector handler that calls a method when a new window is opened. I want the method to do 'something' only if the current window is a forward message window (the window that opens when you click the forward button in an email). My current code works but it works with all new windows, including Reply/ New Email etc.

Any help how I can check to see if the new window is a forward email window?

My code:

...
Outlook.Inspectors olInspectors;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {  ......
        olInspectors = this.Application.Inspectors;
        olInspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Forward_Message_Inspector);
    }

void Forward_Message_Inspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
    {
      //how do I check here if current window is a forward message window?
          //and then do something
    }

Thank you in advance for any help.

Upvotes: 4

Views: 1889

Answers (2)

Eric Legault
Eric Legault

Reputation: 5834

You can wire up your Inspector handler/wrapper to only process windows when the MailItem.Forward event occurs - but you'd also need a MailItem handler/wrapper.

Another approach is to check the values of PR_ICON_INDEX (will be 262 for forwards) or PR_LAST_VERB_EXECUTED (104 for forwards) on the MailItem using the PropertyAccessor object.

Upvotes: 4

Sarvesh Mishra
Sarvesh Mishra

Reputation: 2072

You can check this using Subject of the Email.

void Forward_Message_Inspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
    Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
    if (mailItem != null)
    {
        if (mailItem.Subject.StartsWith("FW: "))
        {
          //do something here
        }
    }
}

You can also do this by analyzing Mail Body

Upvotes: 5

Related Questions