How to get the print format of a email using aspose email in java

I want to get the exact print copy of an email using aspose email. Is it possible to get the print option of an email and save it in a PDF format. If Yes please provide sample code. Thank you.

@Sravani_Pala,

Please use the code snippet given below to save email in PDF format.

FileInputStream fstream=new FileInputStream("Source.msg");
MailMessage eml = MailMessage.load(fstream);

//Save the Message to output stream in MHTML format
ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
eml.save(emlStream, SaveOptions.getDefaultMhtml());

//Load the stream in Word document
com.aspose.words.LoadOptions lo = new com.aspose.words.LoadOptions();
lo.setLoadFormat(LoadFormat.MHTML);
Document doc = new Document(new ByteArrayInputStream(emlStream.toByteArray()), lo);

//Save to disc
doc.save("Result.pdf", SaveFormat.PDF);

We hope that this answered your question. Please feel free to contact us if additional information is required.

Hi Muhammad,

We are using below lines of code,
MailMessage message = new MailMessage();
// Subject
message.setSubject(subject);
// From
message.setFrom(new MailAddress(fromAddress));

// To
message.setTo(to1);

// Body
message.setHtmlBody(messageBody);

com.aspose.email.MhtSaveOptions mhtSaveOptions = new com.aspose.email.MhtSaveOptions();
int iSaveOptions = com.aspose.email.MhtFormatOptions.WriteHeader | com.aspose.email.MhtFormatOptions.HideExtraPrintHeader;
mhtSaveOptions.setMhtFormatOptions(iSaveOptions);

message.save(“SentMail.mhtml”, mhtSaveOptions);

And below is the screenshot.
Here Sent:Sat, 13 Oct 2018 21:02:09 +0900

Here above date is displayed incorrect with utc format.
Also its not similar when we do print.
image.png (11.1 KB)

So we need solution to remove the UTC date format
And also with ASPOSE.EMAIL API there is no print option, usually if we print company logo will be there on top, but here we are adding them manually and also format of print vs saving the mail message in .mhtml / .pdf is different.

Thanks
Arul

@Arul99,

The date is correct according to the email header specifications. rfc5322. Please elaborate your requirement further and also let us know how the date changes while printing. Please share the generated MHTML file as well.