捕获Outlook 2013发送事件 [英] capture the Outlook 2013 Send event

查看:181
本文介绍了捕获Outlook 2013发送事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应捕获Outlook 2013 Send事件的应用程序。我已经使用C#项目来完成所需的任务。

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;
}


推荐答案

以下步骤适用


  1. 创建共享加载项。选择Outlook作为受支持的应用程序。

  2. 在应用程序属性页面中,将Outlook设置为启动程序。

  3. 添加对Microsoft的引用Outlook 11.0对象库。

  4. 导入名称空间:

  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:

使用Outlook = Microsoft.Office.Interop.Outlook;
使用System.Windows.Forms;

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

5。替换原始系统生成的字段:

5.Replace the original system generated fields:

private object applicationObject;
private object addInInstance;

具有以下新字段:(无ItemSend事件)

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。在OnConnection方法中,将所有系统生成的代码替换为以下代码:

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。添加事件处理函数OutlookInspectors_NewInspector:

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.添加事件处理函数OutlookApplication_ItemSend:

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);
}

这篇关于捕获Outlook 2013发送事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆