Problems in saving msg to pdf

I’m getting the same error as mentioned in below link. Could you please let me know whether do you have a fix?

https://forum.aspose.com/t/69839

Thanks,
Albert Samuel

Hi Albert,
Thanks for your request. Could you please attach your document here for testing? We will check the issue and provide you more information.
Best regards,

My Code as given below and attached the input file. I’m getting error in this line of code-

Document msgDocument = new Document(msgStream);

Could you please look into it ASAP ? Thank you!I use Aspose.Words 10.5 .0 .0 and Aspose.Network 4.7 .1 .0

String x;
x = "Sample.msg";
String y;
y = "Sample_out.pdf";
Aspose.Network.Mail.MailMessage msg = Aspose.Network.Mail.MailMessage.Load(x, Aspose.Network.Mail.MessageFormat.Msg);
MemoryStream msgStream = new MemoryStream();
msg.Save(msgStream, Aspose.Network.Mail.MailMessageSaveType.MHtmlFromat);
msgStream.Position = 0;
Document msgDocument = new Document(msgStream);
msgDocument.Save(y, SaveFormat.Pdf);

Hi Albert,
Thank you for additional information. But on my side I can successfully open MHTML document from stream using Aspose.Words. However, Aspose.Words throws an exception when attempt to save the document to PDF. I logged this problem in our defect database. We will let you know once it is resolved.
Best regards,

Thank you, could you please let me know whether is there a way to save as HTML instead of PDF? Because, either PDF or HTML output works good for me.

Hi
Thanks for your request. Conversion to HTML works fine on my side. Here is code I used for testing:

Aspose.Network.Mail.MailMessage msg = Aspose.Network.Mail.MailMessage.Load(@"Test001\Sample.msg", Aspose.Network.Mail.MessageFormat.Msg);
MemoryStream msgStream = new MemoryStream();
msg.Save(msgStream, Aspose.Network.Mail.MailMessageSaveType.MHtmlFromat);
msgStream.Position = 0;
Document msgDocument = new Document(msgStream);
msgDocument.Save(@"Test001\out.html");

Best regards,

I used the same code that you have given and I’m getting error in below line of code

Document msgDocument = new Document(msgStream);

The error message i’m getting as given below.

{“The document appears to be corrupted and cannot be loaded.”}

Inner exception says, {“Parameter is not valid.”}

Could you please advice? Thank you!

Stack Trace details as given below :-

at System.Drawing.Bitmap... ctor(Stream stream)
at xf9a9481c3f63a419.x3cd5d648729cd9b6... ctor(Byte[] imageBytes)
at x011d489fb9df7027.x8e500baeffc6e539.set_xcc18177a965e0313(Byte[] xbcea506a33cf9111)
at Aspose.Words.Drawing.ImageData.set_ImageBytes(Byte[] value)
at Aspose.Words.DocumentBuilder.InsertImage(Byte[] imageBytes, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(Stream stream, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(Stream stream, Double width, Double height)
at Aspose.Words.DocumentBuilder.InsertImage(Stream stream)
at x4e7201a131ebc6f0.xf018334243635fc2.xf8a40478b82d35ca()
at x4e7201a131ebc6f0.xf018334243635fc2.xafe4c84dad991034()
at x4e7201a131ebc6f0.xf018334243635fc2.x22a6d26ddb3dacb9()
at x4e7201a131ebc6f0.xf018334243635fc2.xd5f4297b62020f85()
at x4e7201a131ebc6f0.xf018334243635fc2.xafe4c84dad991034()
at x4e7201a131ebc6f0.xf018334243635fc2.x22a6d26ddb3dacb9()
at x4e7201a131ebc6f0.xf018334243635fc2.xd5f4297b62020f85()
at x4e7201a131ebc6f0.xf018334243635fc2.xafe4c84dad991034()
at x4e7201a131ebc6f0.xf018334243635fc2.x06b0e25aa6ad68a9(Stream xcf18e5243f8d5fd3, Document x6beba47238e0ade6)
at Aspose.Words.Document.x5d4db34d48fb3129(Stream xcf18e5243f8d5fd3, LoadOptions x27aceb70372bde46)

Hi
Thanks for your request. I cannot reproduce this problem on my side. I use Aspose.Words 10.5.0 and Aspose.Network 6.5.0 for testing. Please try using the latest version of both products.
Best regards,

Thank you! Now I use the same version and its working, but since i wanted only the body of e-Mail i used the below code where the Image is coming as blank. Rest all working good. Could you please let me know why the image is coming bank with picture “X” instead of actual image.

Aspose.Network.Mail.MailMessage msg = Aspose.Network.Mail.MailMessage.Load(@"Test\Sample.msg", Aspose.Network.Mail.MessageFormat.Msg);

Document doc = new Document();
DocumentBuilder builder1 = new DocumentBuilder(doc);

builder1.InsertHtml(msg.HtmlBody);

doc.Save(@"Test\out1.html");

Hello
Thank you for additional information. I cannot reproduce the problem on my side. I have sent the HTML document produced by the following code to your e-mail:

Aspose.Network.Mail.MailMessage msg = Aspose.Network.Mail.MailMessage.Load(@"C:\Temp\Sample.msg", Aspose.Network.Mail.MessageFormat.Msg);
MemoryStream msgStream = new MemoryStream();
msg.Save(msgStream, Aspose.Network.Mail.MailMessageSaveType.MHtmlFromat);
msgStream.Position = 0;
Document msgDocument = new Document(msgStream);
msgDocument.Save(@"C:\Temp\out.html");

Best regards,

Thank you! Yes, it worked for me as well, but i don’t want the header part. I just want the body of the e-Mail. I just want the HtmlBody without having the below mentioned Header details.

From: Albert Milton
Sent: 13.10.2011 19:02:27
To: Albert Milton
Subject: Sample(Aspose.Network Evaluation)
Attachments: License.txt

Hi
Thank you for additional information. I suppose the problem might occur because when you simply get body HTML from the message, paths to images are not valid. So Aspose.Words cannot access them. Please try to check the body HTML and see whether paths to images are valid and accessible.
Best regards,

Hi

The paths are valid and images are accesible. Because, the below code works perfectly as you have sent the result in a attachment to my mail. The same input file (Sample.msg) is been used to save as HtmlBody and its not working and image is coming blank as i mentioned in my previous comments. Could you please help?

Aspose.Network.Mail.MailMessage msg = Aspose.Network.Mail.MailMessage.Load(@"C:\Temp\Sample.msg", Aspose.Network.Mail.MessageFormat.Msg);
MemoryStream msgStream = new MemoryStream();
msg.Save(msgStream, Aspose.Network.Mail.MailMessageSaveType.MHtmlFromat);
msgStream.Position = 0;

Document msgDocument = new Document(msgStream);
msgDocument.Save(@"C:\Temp\out.html");

Hi
Thank you for additional information. Of course images will be there when you save to MHTML first. Because in this case, images are stored inside the MHTML file. However, when you simply get HtmlBody of the message, Aspose.Network does not save the images outside. The links to images will be the same:

<img border="0" width="600" height="200" id="Picture_x0020_6" src="cid:image001.jpg@01CC8997.9878C3A0" alt="Description: http://image.exct.net/lib/ff011672706104/m/1/2012MedSeason_Quality.jpg">

As you can see it refers to the internal resource inside MSG or MHTML file. OF course this image will not be accessible when you simply use HTML string.
Try this code and you will notice the same:

Aspose.Network.Mail.MailMessage msg = Aspose.Network.Mail.MailMessage.Load(@"Test001\Sample.msg", Aspose.Network.Mail.MessageFormat.Msg);

using(FileStream fs = File.Create(@"Test001\out.html"))
{
    using(StreamWriter writer = new StreamWriter(fs))
    {
        writer.Write(msg.HtmlBody);
    }
}

Best regards,

The issues you have found earlier (filed as WORDSNET-5371) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.