capture the Outlook 2013 Send event

前端 未结 1 739
梦毁少年i
梦毁少年i 2020-12-06 07:40

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

相关标签:
1条回答
  • 2020-12-06 08:19

    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);
    }
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题