Email HTML Generator

Although it's possible to get the email HTML version of a document by calling getEmailHtml on the editor instance, it's highly advised to generate the email HTML from your backend. You can store the JSON version of the document in your database and you can generate when it's needed. (For example, right before sending the email.)

This way, you don't have to update the HTMLs in your database when something breaks on an email client, because you will get the up-to-date version of the HTML whenever we roll out a fix.

cURL example:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR-API-KEY>" -d '{"document": <DOCUMENT-JSON>, "settings": {}}' https://sdk-api.chamaileon.io/api/v1/emails/generate

You can try it from the client-side with Javascript as well, but keep in mind, that you should only do it for testing purposes. This route needs your API key in the "Authorization" header field, so if you push the following code to production, your API key will be compromised. That is why you should always call this route from your backend.

const genRequest = await fetch('https://sdk-api.chamaileon.io/api/v1/emails/generate', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    document: documentJson
  })
})

if (!genRequest.ok) {
	throw new Error("Auth error")
}

const response = await genRequest.json()

generatedHtmlTextArea.value = response.result

You have to send two properties on a JSON object:

Property Type Description
document object The document object.
settings object Various generator options. Read more below.

The response is a JSON object, and you will find the generated email HTML on the result property.

Settings

There are various generator settings option. They will modify the output of the generator:

Property Type Default Description
vmlBackground boolean true Generate VML backgrounds for mso Outlook versions.
rolePresentation boolean false Add role="presentation" to the layout tables to enhance accessibility.
encodeUrls boolean true Encode URLs.
lineLength number 799 The max. length of lines in the output.
buttonType string "classic" The "classic" button type is a fully clickable one, but there is a "minimal" button type as well which is not fully clickable. You might need the minimal version if your ESP does not support the fully clickable version.
forceHexaColors boolean true If true, all of the color codes are converted to hexa.
templatingLanguage string "handlebars" The output's templating language. Right now, we support "handlebars", "liquid", and "mustage".