Free Support Forum - aspose.com

Invalid HTML using HtmlFormatOptions.WriteHeader


#1

Hi,

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)

Regards,
Michael


#2

@mstrucken,

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.