Question

I'm working on an application that should capture the Outlook 2013 Send event. I have used a C# project to do the required task.

In particular I have used following code to do this task

public Outlook.Application OutlookApplication;
public Outlook.Inspectors OutlookInspectors;
public Outlook.Inspector OutlookInspector;
public Outlook.MailItem OutlookMailItem;
public delegate void ApplicationEvents_11_ItemSendEventHandler(object Item, ref bool Cancel);

applicationObject = application;
addInInstance = addInInst;
OutlookApplication = application as Outlook.Application;
OutlookInspectors = OutlookApplication.Inspectors;
OutlookInspectors.NewInspector += new InspectorsEvents_NewInspectorEventHandler(OutlookInspectors_NewInspector);
OutlookApplication.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(OutlookMailItem_Send);

string strchkTo = OutlookMailItem.To;
string strchk = "hello Welcome to c#";

OutlookInspector = (Outlook.Inspector)Inspector;
if (Inspector.CurrentItem is Outlook.MailItem)
{
   OutlookMailItem = (Outlook.MailItem)Inspector.CurrentItem;
}
Was it helpful?

Solution

The following steps works fine at my side.

  1. Create a Shared Add In. Choose Outlook to be the supported Application.
  2. In the Application Property page, set Outlook to be the start up program.
  3. Add a reference to Microsoft Outlook 11.0 Object Library.
  4. Import the namespace:

    using Outlook = Microsoft.Office.Interop.Outlook; using System.Windows.Forms;

5.Replace the original system generated fields:

private object applicationObject;
private object addInInstance;

with the following new fields: (No ItemSend event)

public Outlook.Application OutlookApplication;
public Outlook.Inspectors OutlookInspectors;
public Outlook.Inspector OutlookInspector;
public Outlook.MailItem OutlookMailItem;

6.In the OnConnection method, replace all the system generated codes with the following ones:

OutlookApplication = application as Outlook.Application;
OutlookInspectors = OutlookApplication.Inspectors;
OutlookInspectors.NewInspector += new   Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(OutlookInspectors_NewInspector);
        OutlookApplication.ItemSend +=new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(OutlookApplication_ItemSend);

7.Add the event handler function OutlookInspectors_NewInspector:

 void OutlookInspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
  {
     OutlookInspector = (Outlook.Inspector)Inspector;
     if (Inspector.CurrentItem is Outlook.MailItem)
     {
                OutlookMailItem = (Outlook.MailItem)Inspector.CurrentItem;
     }

  }

8.Add the event handler function OutlookApplication_ItemSend:

 void OutlookApplication_ItemSend(object Item, ref bool Cancel)
 {
   string strchkTo = OutlookMailItem.To;
   string strchk = "hello Welcome to c#";
   MessageBox.Show(strchk + "\r\n" + strchkTo);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top