I am writing an add-in for Outlook 2010. At one point it needs to delete the Mail items currently selected by the user. I'm using the following code, which works quite well:
Selection selectedMessages = Globals.ThisAddIn.Application.ActiveExplorer().Selection;
// It is possible for a non-mail item to be part of this collection. (One example is when a calendar
// item is in the deleted items folder. Select it and hit this delete button.)
System.Collections.IEnumerator enumerator = selectedMessages.GetEnumerator();
while(enumerator.MoveNext())
{
if (enumerator.Current is MailItem)
{
((MailItem)(enumerator.Current)).Delete();
}
}
My problem is that when I delete messages this way, the normal "undo" operation is not available to the user. It is possible for the user to go to the Deleted Items folder and move the messages back to the Inbox. But it will be confusing for users that are used to just hitting Ctrl-Z or the little "Undo" arrow at the upper-left corner of the screen.
Is there some way I can register this action with the Undo mechanism, or perhaps invoke the "real" delete functionality of Outlook on the message so that Undo is available automatically?
Don't delete the
MailItem
; move it to theolFolderDeletedItems
folder instead. You can useGetDefaultFolder()
to obtain a reference to this folder; see here.