Free Support Forum - aspose.com

MSG to TIFF THROWS ERROR

Getting error when trying to convert MSG file to TIFF.

at Aspose.Email.Printing.MailPrinter.Print(MailMessage message, Stream outputStream, PrintFormat printingFormat)

Hi Stan,


Thank you for writing to Aspose support team.

I have tried the scenario using following code but could not re-produce the issue. The message is saved to MemoryStream which is saved on disc. We can view this file properly by double clicking on it.

It seems that, this issue is specific to the message which you are using for your testing. Please share the message with us so that the problem can be re-produced here and assistance is provided accordingly.

String path = url + “Email_638521\”;<o:p></o:p>

MailPrinter printer = new MailPrinter();

printer.FormattingFlags = Aspose.Email.Printing.MessageFormattingFlags.AutoFitWidth;

//Create or load file

MailMessage msg = new MailMessage("sender@gmail.com", "receiver@gmail.com", "Subject", "Body");

MemoryStream ms = new MemoryStream();

printer.Print(msg, ms, Aspose.Email.Printing.PrintFormat.Tiff);

//Save memory stream to file for viewing

using (FileStream file = new FileStream(path + "output.tiff", FileMode.Create, System.IO.FileAccess.Write))

{

byte[] bytes = new byte[ms.Length];

ms.Read(bytes, 0, (int)ms.Length);

file.Write(bytes, 0, bytes.Length);

ms.Close();

}


//Save message directly to disc

//printer.Print(msg, path + "output_email.tiff", Aspose.Email.Printing.PrintFormat.Tiff);

Attached please see the msg file that caused the error.

Hi Stan,


I have used following code which saves this msg file as TIFF. The memory stream is saved to file and that file can be opened successfully. I have used Aspose.Email for .NET 5.4.0 for testing. The output TIFF files are also attached here for your reference. Please use this latest library and following code in your testing share the feedback with us.

P.S. Please remember to set ms.Posistion = 0 before saving it to file.

String path = url + “Email_638521\”;<o:p></o:p>

MailPrinter printer = new MailPrinter();

printer.FormattingFlags = Aspose.Email.Printing.MessageFormattingFlags.AutoFitWidth;

//Create or load file

//MailMessage msg = new MailMessage("sender@gmail.com", "receiver@gmail.com", "Subject", "Body");

MailMessage msg = MailMessage.Load(path + "30607471_.MSG");

MemoryStream ms = new MemoryStream();

printer.Print(msg, ms, Aspose.Email.Printing.PrintFormat.Tiff);

//Save memory stream to file for viewing

using (FileStream file = new FileStream(path + "outputStream.tiff", FileMode.Create, System.IO.FileAccess.Write))

{

ms.Position = 0;

byte[] bytes = new byte[ms.Length];

ms.Read(bytes, 0, (int)ms.Length);

file.Write(bytes, 0, bytes.Length);

ms.Close();

}

printer.Print(msg, path + "outputFile.tiff", Aspose.Email.Printing.PrintFormat.Tiff);