DOCX > MHTML > EML Conversion Issue with "Content-Disposition" using .NET

Hello,

I faced an issue on converting *.docx file to *.eml. Images from my docx file are shifted to the right after conversion (please check attached screenshot). The way I am doing conversion is shown below:

string input = "C://input.docx";
string result = "C://result.eml";

Document wordDocument = new Document(input);
MemoryStream mhtmlStream = new MemoryStream();
wordDocument.Save(mhtmlStream, SaveFormat.Mhtml);
mhtmlStream.Position = 0;
            
MailMessage message = MailMessage.Load(mhtmlStream, new EmlLoadOptions());
message.Subject = "Subject";
message.From = "FromSomeone@gmail.com";
message.To = "To";

message.Save(result);

As you can see from screenshot, images have been loaded correctly, because their names were shown (“back.png” and “forward.png”). But for some reason they are symmetrically shifted to the right.

My input docx file and generated eml file are also attached.

images_shifted.png (115.0 KB)
input.zip (54.9 KB)

@AlexBilakovskyi

Please note that Aspose.Words mimics the behavior of MS Word. If you convert your document to MHTML using MS Word, you will get the same output.

Could you please ZIP and attach your expected output MHTML along with screenshot of problematic sections of problematic output? We will investigate this issue further and provide you more information on it.

@tahir.manzoor

This was my full code. So I try to convert eml to doc (or docx) and then back to eml. After this conversion I expect to see “result.eml” equal to “input.eml”. But images in result file are shifted. All my files are attached below inside zip archive.

Thanks for quick reaction

string inputEml = "C://input.eml";
string docxConvertedFromEml = "C://convertedFromEmlDoc.doc";
string result = "C://result.eml";

//Convert to doc
MailMessage msg = MailMessage.Load(inputEml);
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions
{
    MailMessageSaveType = MailMessageSaveType.MHtmlFormat, 
    MhtFormatOptions = MhtFormatOptions.None
};
using (MemoryStream ms = new MemoryStream())
{
    msg.Save(ms, mhtSaveOptions);
    Aspose.Words.Loading.LoadOptions loadOptions = new Aspose.Words.Loading.LoadOptions
    {
        LoadFormat = LoadFormat.Mhtml
    };
    Document document = new Document(ms, loadOptions);
    Aspose.Words.Saving.DocSaveOptions saveOptions = new Aspose.Words.Saving.DocSaveOptions();
    document.Save(docxConvertedFromEml, saveOptions);
}

//Convert from doc to eml
Aspose.Words.Document wordDocument = new Aspose.Words.Document(docxConvertedFromEml);
MemoryStream mhtmlStream = new MemoryStream();
wordDocument.Save(mhtmlStream, SaveFormat.Mhtml);
mhtmlStream.Position = 0;

MailMessage message = MailMessage.Load(mhtmlStream, new EmlLoadOptions());
message.Subject = "Subject";
message.From = "FromSomeone@gmail.com";
message.To = "To";

message.Save(result); 

files.zip (73.5 KB)

@AlexBilakovskyi

The position of arrows (images) are changed after conversion from .eml to .mhtml. Your query is more related to Aspose.Email. We are moving this forum thread to Aspose.Email forum where you will be guided appropriately.

@AlexBilakovskyi,
Thank you for the issue description. I reproduced the problem and logged the issue in our tracking system with ID EMAILNET-40224. Our development team will investigate this case. You will be notified when it is fixed.

@AlexBilakovskyi,
Our development team investigated the issue and found that this is not a bug of Aspose.Email. Aspose.Email does not change the HTML body in any way. This is a known issue with different HTML rendering engines for IE and MS Office. If you open the MHTML file in MS Word instead of IE, you will see the expected result.

Useful articles:
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007
Outlook 2013 / 2016 / 2019 / 365 and Word HTML

@Andrey_Potapov

Thanks a lot for your answer and explanation!
For some reason I cannot open my result.eml file via Outlook 2016. Am I doing conversion wrong? May that be a reason? If so, how should I convert it to make him readable by Outlook?

@AlexBilakovskyi,

Could you please clarify what happens when you open the result.eml file in Outlook 2016? Please share a screenshot.

@Andrey_Potapov

When I try to open result.eml via Outlook 2016 I am getting empty page (screeshoot 1). Then when I select “document.html” inside I am getting my page with shifted images (screenshoot 2). To clarify what I am trying to say I recorded a video (attached in archive) of how my input and result files are opening. Hope I explained it correctly.

I expect both my files (input and result) to look and behave in the same way.

screenshoot1.png (32.4 KB)
screenshoot2.png (55.3 KB)
Opening input eml via outlook.zip (8.3 MB)
Opening result eml via outlook.zip (8.3 MB)

@AlexBilakovskyi,
Thank you for the additional information. I reproduced the issue and logged it in our tracking system with ID EMAILNET-40247. Our development team will investigate this case. I will inform you of any progress.

@AlexBilakovskyi,
Our development team investigated this case. This is not an issue of Aspose.Email, but of Aspose.Words. I passed the required technical information to the Aspose.Words support.

@AlexBilakovskyi

We have logged an investigation ticket for your issue as WORDSNET-22315 in our issue tracking system. We will inform you via this forum thread once there is any update available on this issue.