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

Free Support Forum - aspose.com

Invalid HTML using HtmlFormatOptions.WriteHeader


using HtmlFormatOptions.WriteHeader to save an email as html results in invalid html. The opening html element is somewhere inside the body element followed by a second head and body element etc.

Please use the following java code to reproduce the issue:

// Create a new instance of MailMessage class
MailMessage message = new MailMessage();

// Set subject of the message
message.setSubject( "New message created by Aspose.Email for Java" );

// Set body
message.setBody( "Example message body" );
// Set sender information
message.setFrom( new MailAddress( "from@domain.com", "Sender Name", false ) );

// Add TO recipient
message.getTo().addMailAddress( new MailAddress( "to1@domain.com", "Recipient 1", false ) );	
ByteArrayOutputStream bytearrayoutputStream = new ByteArrayOutputStream();

HtmlSaveOptions options = SaveOptions.getDefaultHtml();

options.setEmbedResources( true );
options.setHtmlFormatOptions( HtmlFormatOptions.WriteHeader | HtmlFormatOptions.WriteCompleteEmailAddress );

message.save( bytearrayoutputStream, options );

System.out.println( bytearrayoutputStream.toString( StandardCharsets.UTF_8.name() ) );

Please find attached the expected and the generated html.
html.zip (3.2 KB)



Thank you for contacting Aspose Support.

We were able to reproduce the issue reported by you. We have logged a ticket in our issue tracking system as EMAILJAVA-34468 to investigate this scenario further. We will update you here as soon as additional information is available.

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