Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

c# - capture the Outlook 2013 Send event

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 + "
" + strchkTo);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...