Hi,
I have been having trouble retrieving messages from the Exchange Web Service via Aspose Email IEWSClient.
Retrieval of the message does occur. The problem is that emails containing some “special” characters do not display them as expected when retrieved via IEWSClient. If I open up the email in Outlook and then save it to an MSG file, it saves the special characters and the MapiMessage object can read it and even when its converted from a MapiMessage to a MailMessage it has the special characters. It’s only a problem when retrieving it from the Aspose IEWSClient I cannot get the actual character.
One of the problem character’s is “»”.
Note: you can hold your key and press 0187 on your keyboard’s number pad to produce it.
Our code is similar to this: -<!–[if gte mso 10]>
<![endif]–>
NetworkCredential credential = CredentialCache.DefaultNetworkCredentials;
string MailboxUri = @“https://exchange_hostname/ews/exchange.asmx”;
Aspose.Email.Mail.MailMessage m;
var builder = new ExchangeQueryBuilder();
builder.HasNoFlags(ExchangeMessageFlag.IsRead);
var query = builder.GetQuery();
char lookForChar = ‘»’;
IEWSClient client = EWSClient.GetEWSClient(MailboxUri, credential);
var msgCollection = client.ListMessages(client.MailboxInfo.InboxUri, 1000, query, false);
foreach (
var msgInfo in msgCollection
.Where(
s => s.Subject == “Subject of Problem Email for diagnosis”
)
)
{
var strMessageUri = msgInfo.UniqueUri;
MailMessage emailMessage = client.FetchMessage(strMessageUri);
if ((emailMessage.Body.IndexOf(lookForChar) > -1))
{
Console.WriteLine(“Is Working correctly”);
}
else
{
Console.WriteLine(“Is NOT Working correctly”);
}
}
This returns: -
Is NOT Working correctly
BodyType : PlainText
BodyEncoding : null
PreferredTextEncoding : System.Text.UTF8Encoding
Note that I’ve tried to loop through every permutation of encodings, SaveOptions and MailMessageSaveType’s to see if that would make any difference by saving to a file but it didn’t work.
Note that when I save the email from Outlook it has its Format Text set to “Plain Text”, but when I read it as a MapiMessage and convert it to MailMessage it is "Html"
When I read the file saved by Outlook using the following: -
string fileNameToRead = @“locationOfSavedOutlookFile.msg”;
MapiMessage mapiMsg = MapiMessage.FromFile(fileNameToRead);
// get MailMessageInterpretor instance
MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(mapiMsg .MessageClass);
// get MailMessage instance
MailMessage message = mi.Interpret(mapiMsg);
Console.Write(
string.Concat(
"BodyType : ", (message.BodyType == null) ? “null” : message.BodyType.ToString(), Environment.NewLine,
"BodyEncoding : ", (message.BodyEncoding == null) ? “null” : message.BodyEncoding.ToString(), Environment.NewLine,
"PreferredTextEncoding : ", message.PreferredTextEncoding, Environment.NewLine
)
);
Returns: -
BodyType : Html
BodyEncoding : System.Text.Latin1Encoding
PreferredTextEncoding : System.Text.Latin1Encoding
What is going on here? Am I not converting correctly or is there a bug in the reader?
Thanks
Ralph