挂钩 Outlook 联系人的发送/接收同步事件

发布于 2024-07-25 11:02:19 字数 237 浏览 8 评论 0原文

如何使用 VSTO AddIn 为 Outlook 2007 中的联系人文件夹/联系人项目的 SendAndReceive 事件附加事件处理程序? 我尝试使用:

Application.ActiveExplorer().SyncObjects.ForEach
{
   SyncObject.SyncEnd += \\Do something
}

但它不起作用。

How can I attach an event handler for SendAndReceive event of Contact folders/Contact Items in Outlook 2007 using VSTO AddIn? I tried using:

Application.ActiveExplorer().SyncObjects.ForEach
{
   SyncObject.SyncEnd += \\Do something
}

But it is not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

时光暖心i 2024-08-01 11:02:19

我尝试过

Application.ActiveExplorer().SyncObjects.AppFolders.SyncEnd += \\EventHandler

此挂钩来发送/接收所有默认文件夹。

I tried

Application.ActiveExplorer().SyncObjects.AppFolders.SyncEnd += \\EventHandler

This hooks on to send/receive of all default folders..

归途 2024-08-01 11:02:19

实际上我的需求有点不同,但可能是相同的:
我想在发送/接收后收到文件夹更改(我的情况是约会)的通知。
我的第一个想法(我认为您在同一轨道上)是检查发送/接收事件,也许从中获取一些项目集合或类似的东西,但没有这样的东西可用。 (正如 中所述此论坛帖子

我的第二条路径来自 以下文章:我可以注册文件夹的 Item_AddItem_Change (甚至 Item_Removed)事件(它们是也由发送接收所做的更改触发):

一些代码:

// Get the folder calendar folder and subscribe to the events.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
    Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Items.ItemChange += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
}

// Do something with it.
void Items_ItemAdd(object Item)
{
    logItem(Item, "Add");
}
void logItem(object Item, string Action)
{

    Outlook.AppointmentItem item = Item as Outlook.AppointmentItem;

    File.AppendAllText(@"e:\log.txt", string.Format("Item {0}: {1}", Action, Item));

    if (item != null)
    {
        File.AppendAllText(@"e:\log.txt", " - Appointment: " + item.Subject);
    }
}

Actually my need was a bit different but may be the same:
I wanted to be notified of the changes of a folder (appointments in my case) after a send/receive.
My first thought (and I think you are on the same track) was to check for a send/receive event and maybe get some collection of items out of it or something similar, but no such thing is available. (as is also explained in this forum post)

My second path came from the following article: I can register to the Item_Add and Item_Change (and even Item_Removed) event of a folder (whom are also triggered by the changes done by a send receive):

Some code:

// Get the folder calendar folder and subscribe to the events.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
    Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Items.ItemChange += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
}

// Do something with it.
void Items_ItemAdd(object Item)
{
    logItem(Item, "Add");
}
void logItem(object Item, string Action)
{

    Outlook.AppointmentItem item = Item as Outlook.AppointmentItem;

    File.AppendAllText(@"e:\log.txt", string.Format("Item {0}: {1}", Action, Item));

    if (item != null)
    {
        File.AppendAllText(@"e:\log.txt", " - Appointment: " + item.Subject);
    }
}
好久不见√ 2024-08-01 11:02:19

您可以挂接邮件发送/接收事件,然后检查邮件类型是否为 ContactItem。 这是发送事件的示例。

// hook up the event
this.Application.ItemSend += ThisApplication_SentMail;

然后在您的事件处理程序中检查邮件项目类型;

internal void ThisApplication_SentMail(object item, ref bool cancel)
{
    Outlook.ContactItem contactItem = item as Outlook.ContactItem;

    // mail message is not a ContactItem, so exit.
    if (contactItem == null) return;

    // do  whatever you need to here

 }

You can hook up the mail send/receive event and then check that the mail type is a ContactItem. Here is an example of the Send event.

// hook up the event
this.Application.ItemSend += ThisApplication_SentMail;

then in your event handler you check the mail item type;

internal void ThisApplication_SentMail(object item, ref bool cancel)
{
    Outlook.ContactItem contactItem = item as Outlook.ContactItem;

    // mail message is not a ContactItem, so exit.
    if (contactItem == null) return;

    // do  whatever you need to here

 }
黄昏下泛黄的笔记 2024-08-01 11:02:19

就我而言,我需要在收到新电子邮件后触发一个事件 电子邮件同步后,以便我收到新电子邮件,否则我将不会收到新电子邮件附件。

下面我的解决方案可能会对您有所帮助。

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
     this.Application.NewMail += Application_NewMail;
}
     
private void Application_NewMail()
{
_currentExplorer = Application.ActiveExplorer();
_currentExplorer.Session.SyncObjects[1].SyncEnd += AppFolders_SyncEnd;
_currentExplorer.Session.SyncObjects[1].Start();            
}
    
private void AppFolders_SyncEnd()
{
//Your enter code here
}

In my case, I need to trigger an event after a new email is received & after email sync so that I get a new email, or else I will not receive a new email attachment.

Below my solution may help you.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
     this.Application.NewMail += Application_NewMail;
}
     
private void Application_NewMail()
{
_currentExplorer = Application.ActiveExplorer();
_currentExplorer.Session.SyncObjects[1].SyncEnd += AppFolders_SyncEnd;
_currentExplorer.Session.SyncObjects[1].Start();            
}
    
private void AppFolders_SyncEnd()
{
//Your enter code here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文