Encrypted MSG files

I am trying to walk a folder structure full of MSG files and extract the meta data from each file. Some of the files may be encrypted so I won’t be able to get the body (which is fine).

How can I determine if the file is encrypted and if so still extract the from, cc, subject etc.?

I’m using MapiMessage to load the MSG files in my code:
MapiMessage msg = MapiMessage.FromFile(MSGFile);

Thanks

Hi Richard,


We are sorry for the delayed response.

I have analyzed the information and tried to re-produce the scenario here. I created some sample messages and encrypted them using X509Certificate2 certificate. This encrypted mail was saved on disc and loaded back to MailMessage. It was observed that IsSigned flag is set to “true” after encryption and also the TO, FROM, CC etc. fields were extracted successfully from this encrypted message. However the body of the message was not readable as you also mentioned in your post.

Could you please elaborate how the messages are encrypted and provide us some sample encrypted message file along with the code used to encrypt it if possible. This sample file and detail of encryption will help us to assist you as soon as possible.

We are discussing this issue in more detail with our development team and will write back soon once we get any further information in this regard.

Thanks in advance for your cooperation and understanding.

I guess I should have said it was s/mime encrypted. I opened the MSG file using MapiMessage, not MailMessage. I’m still learning the Aspose tools, do you have a code snippet which shows how to open the MSG file with a MailMessage object?

Thanks so much.

Hi Richard,

You can load a MSG file using MailMessage and then load MapiMessage from this MailMessage as well. Please have a look at the following code for your reference.

//Load the MSG file using MailMessage
MailMessage mailMsg = MailMessage.Load("SampleMsg.msg", MessageFormat.Msg);

//Initiate the MapiMessage from MailMessage
MapiMessage mapiMsg = MapiMessage.FromMailMessage(mailMsg);

You can also refer to the Programmers Guide section of online documentation to gain additional information related to Aspose.Email features and examples. Please feel free to contact us in case of any query/inquiry.

That’s way too easy!
So just to make sure I understand correctly. If the MSG file is s/mime encrypted the IsSigned property will be true and I will still be able to read the other metadata fields.

Thanks again.

One more quick question. Where is the EntryID property in the MailMessage object?

It looks like I need to create the MapiMessage from the MailMessage and then I can get at the Mapi properties via MapiMessage.Properties[MapiPropertyTag.PR_SENDER_ENTRYID]
correct? Or is there a direct way to get it from MailMessage?

I assume creating the MapiMessage will still work without throwing an exception if the MailMessage is mime encrypted (I don’t have any sample encrypted MSG files unfortunately, so debugging is a pain)

Hi Richard,


Yes, you are right. You can get Mapi properties once you get the MapiMessage from MailMessage, and then access any property including the EntryID the same way as you have mentioned.

Regarding creating MapiMessage from encrypted MailMessage, you are right as it won’t throw any exception during this process.

Hi Richard,

You wrote to us:

“So just to make sure I understand correctly. If the MSG file is s/mime encrypted the IsSigned property will be true and I will still be able to read the other metadata fields.”

I would like to share that AE uses S/MIME protocol for encrypting messages.

S/MIME provides two security services: digital signatures and message encryption. MailMessage.Encrypt encrypts and signs a message. That’s why the IsSigned flag is true. But this flag doesn’t signal that a message is definitely encrypted. As a message can be just signed but not encrypted. Now AE doesn’t have an exact method for defining whether a message is encrypted. IsSigned shows ‘true’ only for the following content-type values:

“application/pkcs7-mime”, “application/x-pkcs7-mime”, “multipart/signed”. But it doesn’t guarantee that a message is signed and encrypted at the same time.

For your reference see also the following info:

Understanding S/MIME

Please feel free to write us back if you have any other query in this regard.

Thanks so much for your help. I’m up and running. Great support!

Hi,


We are glad to know that above information was helpful to you. Please feel free to write us back if you have any other query in this regard.