如何用C#VSTO获取outlook创建会议时候的发送事件
时间: 2024-02-18 11:02:05 浏览: 152
您可以通过 Outlook.Application 的 ItemSend 事件来获取邮件或会议发送时的事件。具体步骤如下:
1. 在 Visual Studio 中创建 Outlook 项目。
2. 在 ThisAddIn.cs 文件中添加 ItemSend 事件句柄,代码如下:
```csharp
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// 注册 ItemSend 事件句柄
this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
private void Application_ItemSend(object Item, ref bool Cancel)
{
// 判断是否为 AppointmentItem,即会议预定项
if (Item is Outlook.AppointmentItem)
{
// 处理会议预定发送事件
// ...
}
}
```
3. 在处理会议预定发送事件的代码中,您可以获取会议预定项的各种属性,例如:
```csharp
private void Application_ItemSend(object Item, ref bool Cancel)
{
// 判断是否为 AppointmentItem,即会议预定项
if (Item is Outlook.AppointmentItem)
{
Outlook.AppointmentItem appointment = Item as Outlook.AppointmentItem;
string subject = appointment.Subject;
DateTime start = appointment.Start;
DateTime end = appointment.End;
string location = appointment.Location;
string body = appointment.Body;
// 处理会议预定发送事件
// ...
}
}
```
注意:在 ThisAddIn.cs 文件中注册 ItemSend 事件句柄时,需要使用 ApplicationEvents_11_ItemSendEventHandler 委托,因为 Outlook 2016 或更高版本使用的是 Office 2016 的对象模型。如果您使用的是 Outlook 2010 或更早版本,可以使用 ApplicationEvents_ItemSendEventHandler 委托。
阅读全文
相关推荐



















