mapiMessage.ToMailMessage loses some of the email text when converting a MapiMessage
to a MailMessage.
As a result when we save this email to a PDF the PDF does not have some of the text included
in the email.
To Repro. run the following code:
string filePath = @"C:\tmp\Re Catch up over next few weeks - Copy.msg";
using (var stream = File.OpenRead(filePath))
{
MapiMessage mapiMessage = MapiMessage.FromStream(stream);
MailMessage mailMessage = mapiMessage.ToMailMessage(new MailConversionOptions());
if (mapiMessage.BodyHtml.Contains("6/21: 10:00-3:00pm PT") &&
!mailMessage.HtmlBody.Contains("6/21: 10:00-3:00pm PT"))
{
Console.WriteLine("MapiMessage HTML has more text than MailMessage HTML");
}
}
We have tested the sample code provided and it worked fine. Moreover, we have converted mailMessage to PDF as well and the generated PDF is showing complete text. Please have a look on the generated PDFSaveEmailAsPDF_out.pdf (119.8 KB).
For generating PDF, you may follow the code sample given below:
string filePath = @"D:\sample\" + "Re-Catch-up.msg";
using (var stream = File.OpenRead(filePath))
{
MapiMessage mapiMessage = MapiMessage.FromStream(stream);
MailMessage mailMessage = mapiMessage.ToMailMessage(new MailConversionOptions());
if (mapiMessage.BodyHtml.Contains("6/21: 10:00-3:00pm PT") &&
!mailMessage.HtmlBody.Contains("6/21: 10:00-3:00pm PT"))
{
Console.WriteLine("MapiMessage HTML has more text than MailMessage HTML");
}
else
{
MemoryStream ms = new MemoryStream();
mailMessage.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);
// create an instance of LoadOptions and set the LoadFormat to Mhtml
var loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Mhtml;
// create an instance of Document and load the MTHML from MemoryStream
var document = new Aspose.Words.Document(ms, loadOptions);
// create an instance of HtmlSaveOptions and set the SaveFormat to Html
var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
document.Save(@"D:\sample\" + "SaveEmailAsPDF_out.pdf", saveOptions);
}
}
The app includes the repro file and the code below.
When running this app I get the message:
MapiMessage HTML has more text than MailMessage HTML
And the resulting PDF does not include the line:
6/21: 10:00-3:00pm PT
If you want to try the app, you will need to do a nuget restore, as I did not include the packages
to make the app smaller.
I did not include the license in the test app … as I don’t think it matters ( I can repro the problem when using
a license)
This is the full app:
using System;
using System.IO;
using Aspose.Email;
using Aspose.Email.Mapi;
namespace AsposeEmailTest
{
class Program
{
static void Main(string[] args)
{
string filePath = @“Re-Catch-up.msg”;
using (var stream = File.OpenRead(filePath))
{
MapiMessage mapiMessage = MapiMessage.FromStream(stream);
MailMessage mailMessage = mapiMessage.ToMailMessage(new MailConversionOptions());
if (mapiMessage.BodyHtml.Contains("6/21: 10:00-3:00pm PT") &&
!mailMessage.HtmlBody.Contains("6/21: 10:00-3:00pm PT"))
{
Console.WriteLine("MapiMessage HTML has more text than MailMessage HTML");
}
MemoryStream ms = new MemoryStream();
mailMessage.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);
// create an instance of LoadOptions and set the LoadFormat to Mhtml
var loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml;
// create an instance of Document and load the MTHML from MemoryStream
var document = new Aspose.Words.Document(ms, loadOptions);
// create an instance of HtmlSaveOptions and set the SaveFormat to Html
var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
document.Save(filePath + ".pdf", saveOptions);
}
}
}
In previous observation, we just renamed the file. Now we have reproduced this issue at our end and it has been logged with issue ID “EMAILNET-39118” for further investigation.
You will automatically be notified here once we have more information to share.
The issues you have found earlier (filed as EMAILNET-39118) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan