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);
}
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With