Hello, we have been using mailbee to extract email content and save into our system and recently we have moved to aspose.email.
After doing so, we have noticed that some emails do not have the HtmlBody attribute set. Given below is my code.
Body = mailMessage.IsBodyHtml ? mailMessage.HtmlBody.ToString() : mailMessage.Body.ToString()
Mailbee did not have any such issues and we could always rely on it to provide use the html content.
Is this already a known issue?
Hello @chudamani.khadka,
Welcome to our support forum.
Could you please provide a sample file of such email?
Thanks.
Edit: IsBodyHtml flag seems to be false, which is the expected behavior. I tried loading the same file into mapi message instead of mail message. Doing so I got body content in html format.
please refer the sample mail. You can generate the same mail if you set outlook setting to compose emails as plain text.
test (1).zip (2.1 KB)
Thanks, we’ll take a look and get back to you.
Hi @margarita.samodurova any update regarding this?
Hello @chudamani.khadka,
When an eml message is loaded into MapiMessage, the conversion from eml to msg is performed. As a result of this conversion, the HTML body property is added. To avoid conversion, use MailMessage.
@margarita.samodurova There seems to be some confusion. Currently we are loading the file into MailMessage. This results in missing HtmlBody. This is the problem that we would like to fix.
When I load the message into MapiMessage, I get 3 attributes related to mail body. They are in plain text, html and richtext format.
We would like to know why is it that MapiMessage returns an html body but the MailMessage does not.
We would like to stick to using MailMessage. Ideally, we would like to have the HtmlBody value in MailMessage.
Hello @chudamani.khadka ,
There is no property in Aspose.Email to get the HTML body if there is none in the eml file.
But you can use the following code sample to get the content as HTML:
var eml = MailMessage.Load(@"test (1).eml");
if (!eml.IsBodyHtml)
{
using (var ms = new MemoryStream())
{
eml.Save(ms, SaveOptions.DefaultHtml);
var htmlBody = Encoding.UTF8.GetString(ms.ToArray());
}
}