none
Change Draft Mode RRS feed

  • Question

  • I have written some code that the user can save sent email to a outlook folder. The problem is that it saves it as a draft. Is there anyway to change from a draft mode to sent mode.

    Lawrence D. Wilson

    Thursday, October 6, 2016 4:58 PM

Answers

  • On the low (Extended MAPI) level, the MSGFLAG_UNSENT bit can be removed from the PR_MESSAGE_FLAGS property only before the item is saved for the very first time (MAPI limitation).

    The only OOM item ever created in the sent state is the post item. Create a post item, change its MessageClass property back to IPM.Note, save it, remember the item's entry id, release the post item using Marshal.ReleaseComObject (in case of .Net), then reopen it using Namespace.GetItemfromId - you will have MailItem object in the sent state. You will still need to update/delete the PR_ICON_INDEX property to make sure the icon is right.

    If using Redemption is an option, it allows to set the Sent property (before it is saved) as well as SentOn / ReceivedTime / Sender / SentOnBehalfOf properties.

    Off the top of my head:

    RDOSession rdoSession = new RDOSession();
    rdoSession.MAPIOBJECT = Globals.ThisAddIn.Application.Session.MAPIOBJECT;
    RDOFolder rdoFolder = rdoSession.GetDefaultFolder(rdoDefaultFolders.olFolderSentMail);
    RDOMail rdoItem = rdoInbox.Items.Add("IPM.Note");
    rdoItem.Sent = true;
    rdoItem.Recipients.AddEx("Joe The User", "user@domain.demo", "SMTP");
    rdoItem.Subject = "test";
    rdoItem.Body = "test body";
    rdoItem.UnRead = false;
    rdoItem.SentOn = rdoItem.ReceivedTime = new DateTime(2016, 10, 6, 8, 44, 0);
    rdoItem.Sender = rdoItem.SentOnBehalfOf = rdoSession.CurrentUser;
    rdoItem.Save();


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


    Thursday, October 6, 2016 5:35 PM

All replies

  • On the low (Extended MAPI) level, the MSGFLAG_UNSENT bit can be removed from the PR_MESSAGE_FLAGS property only before the item is saved for the very first time (MAPI limitation).

    The only OOM item ever created in the sent state is the post item. Create a post item, change its MessageClass property back to IPM.Note, save it, remember the item's entry id, release the post item using Marshal.ReleaseComObject (in case of .Net), then reopen it using Namespace.GetItemfromId - you will have MailItem object in the sent state. You will still need to update/delete the PR_ICON_INDEX property to make sure the icon is right.

    If using Redemption is an option, it allows to set the Sent property (before it is saved) as well as SentOn / ReceivedTime / Sender / SentOnBehalfOf properties.

    Off the top of my head:

    RDOSession rdoSession = new RDOSession();
    rdoSession.MAPIOBJECT = Globals.ThisAddIn.Application.Session.MAPIOBJECT;
    RDOFolder rdoFolder = rdoSession.GetDefaultFolder(rdoDefaultFolders.olFolderSentMail);
    RDOMail rdoItem = rdoInbox.Items.Add("IPM.Note");
    rdoItem.Sent = true;
    rdoItem.Recipients.AddEx("Joe The User", "user@domain.demo", "SMTP");
    rdoItem.Subject = "test";
    rdoItem.Body = "test body";
    rdoItem.UnRead = false;
    rdoItem.SentOn = rdoItem.ReceivedTime = new DateTime(2016, 10, 6, 8, 44, 0);
    rdoItem.Sender = rdoItem.SentOnBehalfOf = rdoSession.CurrentUser;
    rdoItem.Save();


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


    Thursday, October 6, 2016 5:35 PM
  • Hello Lawrence,

    Basically you need to set the PR_MESSAGE_FLAGS property (DASL name is http://schemas.microsoft.com/mapi/proptag/0x0E070003). The Outlook object model (PropertyAccessor) doesn't allow to change it, so you will have to use a low-level API - Extended MAPI (or any other wrapper around that API, for example, Redemption). The MSGFLAG_UNSENT flag should be removed.

    Or you can create a Post item in Outlook - it will be created in the sent state (with right flags) and then change the message class. property:

    Msg.MessageClass = "IPM.Note"

    See Cannot set PR_MESSAGE_FLAGS for more information.


    [custom.development]

    Thursday, October 6, 2016 5:54 PM