none
How to detect if a MailItem (that is in the outbox but it is not being sent since I opened it) has been deleted by the user RRS feed

  • Question

  • I have a problem that should be easy to solve but I do not find a good solution.

    I am processing a MailItem that is in the outbox. So as I open it then that mail will not be sent until I do mail.send().

    Now, it takes a long time for me to process that mail... and from time to time I must check if that mail is still there or the user deleted it (or moved it to another folder).

    The way I found is, from time to time, to get the EntryId and call this function:

            /*********************************************************************/
            private bool CheckIfEmailWasDeleted(Outlook.MailItem mail)
            {
                try
                {
                    object item = Application.GetNamespace("MAPI").GetItemFromID(mail.EntryID);
                    if (item == null) return true;
                    return false;
                }
                catch (Exception e)
                {
                    e.ToString();
                    return true; 
                }
            } 
    

    however it does not work if the account belongs to a pop3 account (e.g. gmail) while it works for Exchange account.

    Is there any other way to know if the ítem was deleted?

    Thanks.

    Friday, August 31, 2018 6:33 PM

Answers

  • I finally fixed it.

    In all outbox folders (of all accounts) I register the BeforeItemMove event and here I set a property to that item... so I periodically check for this property and if it exists it means the item has been moved from the outbox (to the deleted items or another folder).

    Thanks anyway

    • Marked as answer by pablo_1975 Tuesday, September 4, 2018 12:07 PM
    Tuesday, September 4, 2018 12:07 PM

All replies

  • Hi pablo_1975,

    According to my research, you can try to use Folder of EWS API and Get-MailboxFolderStatistics of PowerShell to check it. 

    Best Regards,

    Yuki


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, September 3, 2018 11:17 AM
    Moderator
  • thanks but I am in VSTO (Outlook Object Model). I am not in the server side.
    Monday, September 3, 2018 11:22 AM
  • I finally fixed it.

    In all outbox folders (of all accounts) I register the BeforeItemMove event and here I set a property to that item... so I periodically check for this property and if it exists it means the item has been moved from the outbox (to the deleted items or another folder).

    Thanks anyway

    • Marked as answer by pablo_1975 Tuesday, September 4, 2018 12:07 PM
    Tuesday, September 4, 2018 12:07 PM
  • Thank you for having taken your time to provide us with your valuable feedback. Also, If you have any question, or update, please feel free to let me know.

    I wish you a happy life.



    Best Regards,

    Simon



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Tuesday, September 4, 2018 1:13 PM
    Moderator