Is it possible to open a draft in a .pst file, modify it, and then save it back? When I tried this (as MapiMessage/MailMessage), it would then look like a regularly sent email without the draft tag.
For MapiMessage, please try setting the message flags as shown below to achieve this:
mapiMessage.SetMessageFlags(mapiMessage.Flags & ~MapiMessageFlags.MSGFLAG_UNSENT); //Set it to Sent Mode. Remove the ~ sign to save it as draft
Thanks, but for some reason when I try it, it seems like the flags all get set to only MSGFLAG_ZERO. I have to set only the unsent flag for it to save as a draft.
Also, is there a way to tell a message was originally a draft? I wasn’t able to see that flag originally set on a draft or any draft information in the MapiMessage class.
If you load a draft MSG file and use the following code, you will see that the flag setting works fine.
msg = MapiMessage.FromFile("177691\\draft message.msg");
//Find if the message is not sent - reutrns true
Console.WriteLine(Convert.ToBoolean(msg.Flags & MapiMessageFlags.MSGFLAG_UNSENT));
//make the message as sent
var byTemp = ~(MapiMessageFlags.MSGFLAG_UNSENT);
msg.SetMessageFlags(~MapiMessageFlags.MSGFLAG_UNSENT);
Console.WriteLine(Convert.ToBoolean(msg.Flags & MapiMessageFlags.MSGFLAG_UNSENT));
The MSGFLAG_ZERO is because there may not be other flags set and hence when all bits of this become 0, it results in this MSGFLAG_ZERO.
You can use the statement:
//Find if the message is not sent - reutrns true
Console.WriteLine(Convert.ToBoolean(msg.Flags & MapiMessageFlags.MSGFLAG_UNSENT));
to check if the message originally a draft or not.
Thanks for the sample code, I have observed that it works if try it on a newly created draft message.
The problem seems to be happening when I try to reply to a message in Outlook and do not send (save as draft). There will be a message in the folder with a red draft tag, but it looks like I have to actually load and reload the message in the drafts folder (or wherever it was placed), is that correct?
Updating existing messages in a PST can be done through FolderInfo.ChangeMessages, but this doesn’t provide any support for marking existing item as sent/unsent. You need to load, modify, remove the old one and add the modified one manually.
Thank you for the help, I was able to figure out the deleting with the message ID strings as well
You are welcome and thank you for sharing the feedback.