Hello,
I’ve an email stored as .msg. This email is not sent, so when the .msg file is opened, the user can change the content of the mail. I want to forbid this.
I’ve found another thread that just asked the opposite, but I didn’t suceed to make it works my way.
Here is the code I tried:
var email = MailMessage.Load(@“Test.msg”, MessageFormat.Msg);
MapiMessage mapiMsg = MapiMessage.FromMailMessage(email);
mapiMsg.SetMessageFlags(mapiMsg.Flags & ~MapiMessageFlags.MSGFLAG_UNSENT);
email.Save(@“Test2.msg”, MailMessageSaveType.OutlookMessageFormat);
when I open Test2.msg, it’s still in edit mode.
Do you know how to “clear” the unsent flag ?
Thank you,
Fab
Hi Fab,
//Load an Unsent message
MailMessage mailMsg = MailMessage.Load(“UnsentMsg.msg”);
//Remove the header that determines the message as Unsent
mailMsg.Headers.Remove(“X-Unsent”);
//Save the message
mailMsg.Save(“TestOut.msg”, MailMessageSaveType.OutlookMessageFormat);
I didn’t know it was based on an header
Thank you for your very quick answer, it works perfectly !
Hi Fab,
Thanks for the feedback and its good to know that your requirements are met now.
In addition, I tried the following code sample and it worked as well for me for an Unsent/Editable message.
Sample Code:
MapiMessage mapi = MapiMessage.FromFile("Unsent.msg");
mapi.SetMessageFlags(mapi.Flags & ~MapiMessageFlags.MSGFLAG_UNSENT);
mapi.Save("UnEditible.msg");
Fabske:
Here is the code I tried:
var email = MailMessage.Load(@"Test.msg", MessageFormat.Msg);
MapiMessage mapiMsg = MapiMessage.FromMailMessage(email);
mapiMsg.SetMessageFlags(mapiMsg.Flags & ~MapiMessageFlags.MSGFLAG_UNSENT);
email.Save(@"Test2.msg", MailMessageSaveType.OutlookMessageFormat);
When I open Test2.msg, it's still in edit mode.
Aah ok
Thank you for solving this problem using 2 different ways
Hi Fab,
pls can i have full code in vb.net
Thanks
hi
i tried this code, still i get editable msg file, here the code
Dim mapi As Mapi.MapiMessage = MapiMessage.FromFile(“UnsentMsg.msg”)
mapi.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT & MapiMessageFlags.MSGFLAG_FROMME)
mapi.Headers.Remove(“X-Unsent”)
mapi.Save(UnsentMsg1.msg)
hi , Yes it working.
Thanks