Home > Software engineering >  How can I determine if an Outlook MailItem is an unsaved draft?
How can I determine if an Outlook MailItem is an unsaved draft?

Time:03-26

As far as I can find there is no property on a MailItem one can access to discover if a MailItem is a draft.

One could check MailItem.Categories and see if it includes Drafts but this seems insufficient because:

Drafts don't have to be stored in the Drafts folder, they can be dragged and dropped into other folders.

The fact that a draft email retains its draftyness even if moved out of the Drafts folder indicates there must be some other way in which a MailItem is marked as a draft, but I haven't been able to find it.

Suggestions?

CodePudding user response:

New items don't have the EntryID property set. The value is assigned by the store provider when an item is saved to the store.

If the item is already saved to the store you can use the PR_MESSAGE_FLAGS property value which contains a bitmask of flags that indicate the origin and current state of a message.

This property is initialized by the client or message store provider when a message is created and saved for the first time and then updated periodically by the message store provider, a transport provider, and the MAPI spooler as the message is processed and its state changes.

Try to check for the MSGFLAG_UNSENT value which stands for the following:

The message is still being composed. It is saved, but has not been sent. The client or provider has read/write access to this flag until the first IMAPIProp::SaveChanges call and read-only thereafter. If a client doesn't set this flag by the time the message is sent, the message store provider sets it when IMessage::SubmitMessage is called. Typically, this flag is cleared after the message is sent.

See PidTagMessageFlags Canonical Property for more information about possible values.

CodePudding user response:

Use the MailItem.Sent property - it will be false for the draft (editable) messages.

  • Related