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

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

问题描述

我正在使用 ApplicationEvents_11_ItemSendEventHandler(请参阅 http://msdn.microsoft.com/en-us/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.

是否有替代事件在 项目实际发送后触发?我读过这篇博文;http://easyvsto.wordpress.com/2010/07/27/how-to-save-mail-content-when-a-mail-is-sent-from-outlook/ 但我警惕依赖于出现在已发送邮件文件夹中的邮件,考虑到用户可以禁用此功能.

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

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

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