Getting Email templates from API

We have requirement where email templates are stored in some another app/repository and needs to be fetched over API call. I want to know how can we replace dynamic values if any present in such templates ? I know Email connector module allows to replace tokens , but not aware how it can be done when we fetch Templates from API call.   Thanks .
2 answers

Hello Shriram, 


Do these templates are made with the email connector module or with another module, software, template provider?


If created with the module you can try to see if everything imports well in your application including the tokens and including the relationship to the tokens, maybe you need to extra refresh the mx reflection module or need to make some other adjustments.


If it is created with other software then i would advise to first make yourself familiar with how the email connector module uses its entities to provide the token service and template service, after you can compare the email connector template with the third pary template and you need to map the right fields and create the right logic to transfrom the external template to the email connector template.


Hope this helps,


Good luck


Hi Shriram,


Are the templates to be fetched only once or every time you need to send a specific email?


If it is only a one time thing, I suggest to, for each template fetched via API:

  • Create a Mendix template
  • Add the HTML retrieved from the API to the newly created template's content
  • Manually replace the tokens with Mendix tokens - with format {%Token%}.
  • Then use these newly created templates throughout your app.


If the templates are to be fetched in runtime every time you need to send an email:

After retrieving the template via API, you can use replaceAll() to replace all occurrences of a dynamic value with the actual value. Then create an EmailMessage, add your $HTMLBody to it and send the email.