It looks like the user defined properties are not actually present in EmailMessage .MimeContent.Content
. They lack corresponding counterparts in the MIME standard and are possibly stored beside the MIME content in Exchange, not as a part of it.
To make sure this is indeed the case, try saving the MIME content into a file:
System.IO.File.WriteAllBytes("message.eml", ewsmessage.MimeContent.Content);
And open it with Notepad or other simple text editor to see what's actually inside. Are there any of your extended properties?
If not, you will have to write a bit of custom code to convert them yourself. MailMessage
doesn't have any extended properties (because MIME lacks support for them), but you might use custom message headers to store them, for example. A code similar to this might to the trick:
// create an instance of MailMessage
var message = new Rebex.Mail.MailMessage { Silent = false };
// load the message
message.Load(ewsmessage.MimeContent.Content);
// convert extended headers
foreach (var property in ewsmessage.ExtendedProperties)
{
string headerName = "X-Exchange-" + property.PropertyDefinition.Name;
string headerValue = property.Value.ToString();
message.Headers.Add(headerName, headerValue);
}
(Please note that this assumes that property.PropertyDefinition.Name
is always defined and has a MIME-friendly name, and that property.Value.ToString()
returns a usable string. Some additional work might be needed to make it suitable for your scenario.)