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 only have to generate it 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/v2/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/v2/emails/generate", {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
document
})
})
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 email 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.
There are various generator settings options. They will modify the output of the generator:
Property | Type | Default | Description |
---|---|---|---|
lang | string | "en" | The language code that we add to the <html> tag |
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" |
Chamaileon supports three button types: classic – Fully clickable button using advanced HTML. May cause issues (e.g. duplicated buttons, broken visibility settings) when emails pass through strict Outlook Exchange servers. compact – Fully clickable with a simpler structure. Use this if classic causes rendering issues. minimal – Only the text inside the button is clickable. Ideal when full clickability is turned off or not supported by your ESP. |
forceHexaColors | boolean | true | If true, all of the color codes are converted to hex color values. |
templatingLanguage | string | "handlebars" | The output's templating language. Right now, we support handlebars , liquid , mustache , mailchimp and acc which is shortened from Adobe Campaign Classic. |
useFullwidthMarker | boolean | false | Add a wrapper HTML comment marker for the fullwidth elements. |
generatorMode | string | "classic" | Can switch between the supported generator modes: table-desktop , hybrid , div-only and classic |
You can read more about our generator settings here
We put together a demo and you can check out the code here.
You can also check out the email generator on the Chamaileon SDK Playground.