Event on “Item Sent” in Outlook

亡梦爱人 提交于 2019-12-19 06:42:15

问题


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.

Edit: 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);

And my method...

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

回答1:


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).

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

See this form post for reference.


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


来源:https://stackoverflow.com/questions/12515612/event-on-item-sent-in-outlook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!