Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 454
Polzi Avatar asked Jan 09 '23 04:01

Polzi


2 Answers

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

like image 164
Sarvesh Mishra Avatar answered Jan 11 '23 23:01

Sarvesh Mishra


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.

like image 25
Eric Legault Avatar answered Jan 11 '23 23:01

Eric Legault