none
Can sending email be cancelled in Close event Outlook 2010? RRS feed

  • Question

  • Hi,

    I have an OL2010 vsto addin. I subscribed a new email's Close event. In the Close event handler, I set cancel=true. I thought the inspector should stay open based on the documentation. But the inspector closed, and the mail was sent out. 

    Can I cancel sending email in Close event? I know I can cancel the sending in sent event.

    Thanks

    jhou

    Friday, April 5, 2013 2:59 PM

Answers

  • If this is a new email that you want to prevent from sending, handle the Send event instead.  Also try refraining from using any return statements - I seem to remember this causing problems.  Just set Cancel = true and let the event finish on its own.

    If you just want to handle the Close event, make sure you are not calling the Close method yourself anywhere, as in that case the Close event can only be cancelled if you call Close(olPromptForSave).


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    • Marked as answer by jhou Friday, April 5, 2013 5:35 PM
    Friday, April 5, 2013 3:46 PM
    Moderator

All replies

  • The Inspector should remain open.  Can you show your code?

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Friday, April 5, 2013 3:02 PM
    Moderator
  • When a new inspector created, we wrapped the current mailItem in a wrapper, and subscribe the close event as show bellow:

    public OpenMailItem(Outlook.MailItem item)
            {
                m_MailItem = item;
                ((Outlook.ItemEvents_10_Event)m_MailItem).Close += new Outlook.ItemEvents_10_CloseEventHandler(Event_Close);
                ((Outlook.ItemEvents_10_Event)m_MailItem).Send += new Outlook.ItemEvents_10_SendEventHandler(Event_Send);
                m_MailItem.AfterWrite += new Outlook.ItemEvents_10_AfterWriteEventHandler(Event_AfterWrite);
               
            }
        
     void Event_Close(ref bool Cancel)
     {
                Cancel = true;
                return;
    }             
               
    Do you think the email should not be sent either?

    Friday, April 5, 2013 3:27 PM
  • If this is a new email that you want to prevent from sending, handle the Send event instead.  Also try refraining from using any return statements - I seem to remember this causing problems.  Just set Cancel = true and let the event finish on its own.

    If you just want to handle the Close event, make sure you are not calling the Close method yourself anywhere, as in that case the Close event can only be cancelled if you call Close(olPromptForSave).


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    • Marked as answer by jhou Friday, April 5, 2013 5:35 PM
    Friday, April 5, 2013 3:46 PM
    Moderator