Embedded Global Styles Corrupt HTML Output when Converting Email

image.png (35.2 KB)
Global styles in embedded mail html body affects any html tag in converted email to html. This could effect "Subject, sender … " headers at generated html via Aspose.
Is there any standard way to deal with global styles at email html body with Aspose ? Of course I we could edit body before conversion, but maybe Aspose has already implemented way.

aspose-email-21.6
in_out.zip (12.3 KB)

FileOutputStream out = new FileOutputStream(".\\html2.html");
FileInputStream in = new FileInputStream(".\\17a14f410d08de53.eml");
EmlLoadOptions emlOptions = new EmlLoadOptions();
emlOptions.setPreserveTnefAttachments(false);
emlOptions.setPreserveEmbeddedMessageFormat(false);
emlOptions.setPrefferedTextEncoding(StandardCharsets.UTF_8);

MailMessage message = MailMessage.load(in, emlOptions);

HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
htmlSaveOptions.setCheckBodyContentEncoding(true);  

int iSaveOptions = HtmlFormatOptions.WriteCompleteBccEmailAddress | HtmlFormatOptions.WriteCompleteCcEmailAddress 
        | HtmlFormatOptions.WriteCompleteFromEmailAddress | HtmlFormatOptions.WriteCompleteEmailAddress 
        | HtmlFormatOptions.WriteHeader | HtmlFormatOptions.DisplayAsOutlook;
htmlSaveOptions.setHtmlFormatOptions(iSaveOptions);

message.save(out, htmlSaveOptions);

@mrila,
Thank you for the issue description. I reproduced the problem and found no way to fix it via Aspose.Email API. It looks like this should not be happening. As you mentioned above, you can change the EML body using getHtmlBody and setHtmlBody methods of MailMessage class. But I added a ticket with ID EMAILJAVA-34926 in our tracking system. Our development team will investigate this case. I will inform you of any progress.

The issues you have found earlier (filed as EMAILJAVA-34926) have been fixed in this update.

@mrila,
Our development team investigated the issue. You can overwrite the style settings of headers as shown below:

HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();

// print header default styles
System.out.println(htmlSaveOptions.getCssStyles());
// modify styles
htmlSaveOptions.setCssStyles(htmlSaveOptions.getCssStyles().replace(
        ".headerLineTitle\r\n\t{", 
        ".headerLineTitle\r\n\t{\r\n\t\tline-height:1;"));

htmlSaveOptions.setCheckBodyContentEncoding(true);

int htmlFormatOptions =
    HtmlFormatOptions.WriteCompleteBccEmailAddress |
    HtmlFormatOptions.WriteCompleteCcEmailAddress |
    HtmlFormatOptions.WriteCompleteFromEmailAddress |
    HtmlFormatOptions.WriteCompleteEmailAddress |
    HtmlFormatOptions.WriteHeader |
    HtmlFormatOptions.DisplayAsOutlook;

htmlSaveOptions.setHtmlFormatOptions(htmlFormatOptions);

message.save(out, htmlSaveOptions);

More examples: Loading and Saving Message
API Reference: HtmlSaveOptions class