none
How to check if MailItems in outbox are being sent or not RRS feed

  • Question

  • Hi!

    I have a VSTO Outlook addin. This addin loops through all outbox of all mailboxes. I need to know how to check if a given email that is in the outbox is really being sent (in other words, if it is in italic) or if it has been opened by the user and closed (in this case it will not be sent and it's not in italic).

    Is there any property that can help me to check this?

    Thanks.

    Friday, October 26, 2018 1:22 PM

All replies

  • As soon as you touch a message with the Outlook Object Model, the submission process is aborted. Don't do that.

    Also keep in mind that a message can be submitted from any folder, Outbox is just an eye candy used by Outlook.

    When you send a message in Outlook, it simply sets the MSGFLAG_SUBMIT bit ( = 4) in the PR_MESSAGE_FLAGS property. The transport provider sees a message with that bit set and start the submission process. Tightly bound store-transport providers (such as online Exchange store, but not cached store) submit the message immediately.

    Your best option is to read the PR_MESSAGE_FLAGS property without opening the message. You can do that either in OOM using MAPIFolder.GetTable. - set Table.Columns to request PR_MESSAGE_FLAGS (DASL name http://schemas.microsoft.com/mapi/proptag/0x0E070003) and the entry id (so that you can open the message later using Namespace.GetItemFromID if you need to). Or you can use Redemption and its MAPITable.ExecSQL method to request these two properties.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!



    Friday, October 26, 2018 4:31 PM
  • Thanks Dmitry, but I always get the decimal value 29 (bit is set) even if the message is not "in italic".

    Suppose you have two messages, one really being transmitted (it is in italic) and another that was already opened by the user so it will not be transmitted until you open it and click on send again. In both cases this PR_MESSAGE_FLAGS  value is 29.

    Another question that is related... Suppose I do in the ItemSend this:

                                mail.PropertyAccessor.SetProperty(

    http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/MyId, szIDStringValue);

    then in that ItemSend event I do this so the message is not sent:

                            mail.DeferredDeliveryTime =

    DateTime.Now.AddDays(1);

                            mail.Save();

    So the email will be "stuck" in the outbox. Then another thread has to find this email so it basically tries:

                        Outlook.Table table = outboxFolder.GetTable("");
                        if (table != null)
                        {
                            table.Columns.Add("EntryID");
                            table.Columns.Add(http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/MyId);
                            while (!table.EndOfTable)
                            { 
                                Outlook.Row row = table.GetNextRow();
                                string szEntryIDGot = row["EntryID"];
                                foreach (object oValueGot in row.GetValues())
                                {
                                    OutputDebugStringEx.Report("=====>Value got: " + oValueGot.ToString()); 
                                }
                                
    
                            }
                        }
    

    Problem is that

     table.Columns.Add(http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/MyId);

    gives an error (something like "The property "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/MyId" does not accept this operation.")

    Monday, October 29, 2018 5:18 PM
  • I don't see your code ever retrieving the PR_MESSAGE_FLAGS property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, October 29, 2018 5:24 PM
  • Hi Dmitry,

    Well, my original code retrieved it by instead of doing:

     table.Columns.Add(http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/MyId);

    I did:

     table.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x0E070003");

    but it was getting 29 in both cases.

    Monday, October 29, 2018 6:37 PM
  • 29 = 0x1D = MSGFLAG_HASATTACH (0x10) + MSGFLAG_UNSENT (0x08) + MSGFLAG_SUBMIT (0x04) + MSGFLAG_READ (0x01)

    It is what it is ... Do you see the same value in OutlookSpy (go to the Outbox folder, click IMAPIFolder button, go to the GetHierarchyTable tab, select the message, locate the PR_MESSAGE_FLAGS property)?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, October 29, 2018 6:56 PM