none
[Outlook AddIn] Delete a MailItem from draft on close RRS feed

  • Question

  • Hi,

    I've got an Outlook addIn. It displays a button in the creating mail window.
    An event is handled when I click on this button. When this event occurs, I need to know the mail's To field.
    MailItem.To returns null. So, to get it anyway, I saved the MailItem (MailItem.save()). It saves the mail into draft box. Then I can get the "To" field.

    However, I want the draft to be deleted when I close the window of mail writing. I put an onClose event which contains a Marshal.ReleaseComObject(mailItem) and MailItem.delete().

    The point is that the delete method catch an exception and the mail isn't deleted from the draft.

    Then, I could I delete it when the mail writing window is closed ?

    Sorry if my english language isn't that good, it's not my native one.

    Regards,
    Kirjava

    Wednesday, March 21, 2012 9:02 AM

Answers

  • You need to start the timer in MailItem.Close (or Inspector.Close?) event.

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Wednesday, March 21, 2012 11:48 AM

All replies

  • Hello,

    Deleting a MailItem in the Close event of this MailItem doesn't make sense. Try deleting it after a delay. You need to use a System.Windows.Forms.Timer. Its event fires on the main thread and this is essential since the Outlook object model must be accessed on the main thread only.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Wednesday, March 21, 2012 9:33 AM
  • Hi,

    Thank you for a so fast answer !
    I could put a timer, but I don't know when to start it. I don't know when will the user click on close or even if he will.

    Or maybe did I miss something in your answer ?

    Regards,

    Wednesday, March 21, 2012 9:51 AM
  • You need to start the timer in MailItem.Close (or Inspector.Close?) event.

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Wednesday, March 21, 2012 11:48 AM
  • I tried what you suggested and it works.
    Thank you very much.

    Wednesday, March 21, 2012 2:11 PM