We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Printing MSG file to MemoryStream


I'm facing some issues with printing msg files to memory stream using the MailPrinter.

It works well with FileStream ,

but when try printing to MemoryStream and then save it to local file - the file is corrupted.

Any clue?



Hi Asaf,

Thanks for writing to Aspose.Email support team.

We have analyzed the issue and have reproduced it here successfully. It seems to be a bug and we have provided all the information to the development team. We will write back here as soon as some feedback is provided by the developers.

Your patience and understanding is highly appreciated in this regard.

This issue is logged in our issue tracking system as NETWORKNET-33506.

Hi Asaf,

Thanks for your patience.

Please try the following sample code which prints a sample mail message to memory stream and then save it to local file. If you still face any problem, please feel free to write us back.

static void Main(string[] args)
//Declare message as an MailMessage instance
MailMessage message = new MailMessage("user1@domain.com", "user2@domain.com",“My First mail”,“Test Body”);

//Set message date to current date and time
message.Date = DateTime.Now;

//Instantiate an instance of MailPrinter
Aspose.Email.Printing.MailPrinter printer = new Aspose.Email.Printing.MailPrinter();

//Direct message, printing to file
printer.Print(message, “FileToPrnt.tiff”, Aspose.Email.Printing.PrintFormat.Tiff);
printer.Print(message, “FileToPrnt.XPS”, Aspose.Email.Printing.PrintFormat.XPS);

//Message in memory, stream printing to file
PrintMemStrToFile(“MemStrToPrnt.XPS”, Aspose.Email.Printing.PrintFormat.XPS, printer, message);
PrintMemStrToFile(“MemStrToPrnt.tiff”, Aspose.Email.Printing.PrintFormat.Tiff, printer, message);

static void PrintMemStrToFile(string fileName, Aspose.Email.Printing.PrintFormat printFormat,
Aspose.Email.Printing.MailPrinter printer, MailMessage message)
MemoryStream memStr = new MemoryStream();
printer.Print(message, memStr, printFormat);
memStr.Seek(0, SeekOrigin.Begin);
FileStream file = new FileStream(fileName, FileMode.Create, System.IO.FileAccess.Write);
byte[] bytes = new byte[memStr.Length];
memStr.Read(bytes, 0, (int)memStr.Length);
file.Write(bytes, 0, bytes.Length);

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan