Custom Layout and Date Format for Email Converters

P
Paulius
ConvertAPI

The EML and MSG converters now let you supply your own HTML layout for the converted email. TemplateFile takes an HTML page with placeholders for the header fields and the message body, replacing the built-in layout. DateTimeFormat sets how the sent date is printed. Both parameters are optional, so conversions that leave them out run exactly as before.

Highlights

  • Both parameters are available on every EML and MSG converter, across the PDF, JPG, PNG, TIFF and WEBP outputs.
  • A template is plain HTML with {{subject}}, {{from}}, {{to}}, {{cc}}, {{sent}} and {{emailContent}} placeholders. Pass it as a URL or as file content.
  • The email body is rendered in its own isolated block, so the message CSS cannot affect your page and your CSS cannot affect the message.
  • TemplateFile applies to the top-level email. Converted attachments keep the built-in layout, and they do follow DateTimeFormat.
  • Setting TemplateFile overrides ConvertHeader, because the template itself decides which header fields appear.

Parameters

  • TemplateFile (file, html or htm) - the HTML page used to lay out the converted email. Defaults to the built-in template.
  • DateTimeFormat (string) - a .NET custom date and time format for the sent date, for example yyyy-MM-dd HH:mm. Defaults to US style with a 12-hour clock.

Try it out