gpt4 book ai didi

c# - 捕获 Outlook 2013 发送事件

转载 作者:太空狗 更新时间:2023-10-29 22:59:22 26 4
gpt4 key购买 nike

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

特别是我使用了下面的代码来完成这个任务

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. 导入命名空间:

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

5.替换原来系统生成的字段:

private object applicationObject;
private object addInInstance;

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

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

6.在OnConnection方法中,将所有系统生成的代码替换为以下代码:

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:

 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:

 void OutlookApplication_ItemSend(object Item, ref bool Cancel)
{
string strchkTo = OutlookMailItem.To;
string strchk = "hello Welcome to c#";
MessageBox.Show(strchk + "\r\n" + strchkTo);
}

关于c# - 捕获 Outlook 2013 发送事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21628357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com