Reputation: 116528
I have a .NET application which uses the Microsoft.Office.Interop.Outlook
interop assembly.
The application opens a new Outlook MailItem
and then would like to record a log entry if the email was sent (via the user clicking Send), or know if it was closed without sending (either saved as a draft or discarded).
Capturing when the item is sent can be done easily enough by subscribing to the ItemEvents_10_Event.Send
event.
However, for capturing when the item is closed, I could only find the ItemEvents_10_Event.Close
event. But, this event fires when the item is closing, not when the item is closed. Worse yet, the user still has a chance to cancel the action after I receive the event. What happens is:
MailItem
.ItemEvents_10_Event.Close
is fired.Is there a way to either:
A bonus would be if I could differentiate if the email was closed and discarded vs saved as a draft.
Upvotes: 1
Views: 3536
Reputation: 154
Use the inspector close event:
inspector = mailItem.GetInspector;
((InspectorEvents_10_Event) inspector).Close += CloseEventHandler;
void CloseEventHandler(){
//execute only when email window is closed or closing
// without problem with confirmation dialog (yes/no/cancel)
}
To resolve closing or closed problem, you can check mailItem send event. If it has fired, then "closing", otherwise, user closed window without sending email.
Upvotes: 6