关于“已发送项目"的事件在Outlook中 [英] Event on "Item Sent" in Outlook

查看:144
本文介绍了关于“已发送项目"的事件在Outlook中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ApplicationEvents_11_ItemSendEventHandler(请参阅 http://msdn.microsoft.com/zh-cn/library/microsoft.office.interop.outlook.applicationevents_11_itemsendeventhandler.aspx ),以便在从Outlook发送项目时进行一些处理.

I'm using ApplicationEvents_11_ItemSendEventHandler (see http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.applicationevents_11_itemsendeventhandler.aspx) to do some processing when an item is sent from Outlook.

但是,由于此事件在发送"而不是发送"时触发,因此我无法获取某些信息,例如发件人,发送时间等.

However, as this event fires on "send", rather than "sent", I'm unable to obtain certain information, such as the sender, sent time etc.

是否有其他事件在实际发送商品后触发 ?我已经阅读了这篇博客文章;

Is there an alternative event that fires after the item has actually sent? I've read this blog post; http://easyvsto.wordpress.com/2010/07/27/how-to-save-mail-content-when-a-mail-is-sent-from-outlook/ but I'm wary of depending on items appearing in the sent items folder, considering that a user can disable this feature.

我应该补充一点,我实际上已经尝试过监视已发送邮件文件夹"方法,并且注意到ItemAdd事件似乎只对我发送的第一封电子邮件触发,然后在我重新启动Outlook之前不会再次出现.我的代码如下;

I should add that I actually have tried the "watch the sent items folder" approach and have noticed that the ItemAdd event only seems to fire for the first email I send, then not again until I restart Outlook. My code is as follows;

var sentMail = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
sentMail.Items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);

还有我的方法...

void Items_ItemAdd(object item)
{
    MessageBox.Show(((Outlook.MailItem)item).Subject);
}

推荐答案

如果使用模式对话框( WPF/Winforms MessageBox ),则只会获得第一个事件触发器.您必须实现非阻塞事件处理程序(可能是项目排队策略).

If you use a modal dialog (WPF/Winforms MessageBox), you will only get the first event trigger. You must implement a non-blocking event handler (possibly an item queuing strategy).

不要使用阻塞的UI调用模式对话框-Outlook将注意到UI被阻塞,并忽略触发后续中断.

Don't use the blocking UI call modal dialogs - Outlook will notice the UI is blocked and ignore triggering subsequent interrupts.

请参见此表格以供参考.

如果您担心用户控制已发送邮件"存储的首选项,只需使用以下代码片段覆盖它们...

If you are worried about the users preferences for controlling Sent Item storage, just override them using the following snippet...

MailItem.DeleteAfterSubmit = false; // force storage to sent items folder (ignore user options)
Outlook.Folder sentFolder = ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
if (sentFolder != null)
    MailItem.SaveSentMessageFolder = sentFolder; // override the default sent items location
MailItem.Save(); 

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

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