From f020671f2ca546e53572d93390ea4a9322700437 Mon Sep 17 00:00:00 2001
From: FORESTIER Fabien <fabien.forestier@soprasteria.com>
Date: Thu, 30 Jan 2020 17:18:59 +0100
Subject: [PATCH] Add doc for email templates

---
 docs/components/services/mailer.md | 31 +++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/docs/components/services/mailer.md b/docs/components/services/mailer.md
index b4ec516..1bc69cf 100644
--- a/docs/components/services/mailer.md
+++ b/docs/components/services/mailer.md
@@ -34,9 +34,38 @@ However the service does not send this JSON directly to the distant SMTP server.
 
 NestJS provides a [swagger module](https://docs.nestjs.com/recipes/swagger) that can be easily integrated. Using specific annotations alongside your endpoints declaration, this module will automatically generates a swagger documentation, reachable at `/api-doc`.
 
+## Templates
 
+In order to generate responsive (on most-popular email clients) email templates, we use the framework [MJML](https://mjml.io/).
 
-## Templates
+There are different ways to install it, an easy one is with `npm`.
+
+```bash
+npm install -g mjml
+```
+
+It uses its own file extention (`.mjml`) and syntax that abstracts the whole layer of complexity related to responsive email design. Once the template done and the content updated we can convert the mjml syntax to html using the following command:
+
+```
+mjml my-file.mjml -o my-file.html
+```
+
+As we needed to add some dynamic content in our mails, we used the power of template literals. Indeed when we want to add some dynamic content in the template, we used the following syntax:
+
+```ts
+${myVariableName}
+```
+
+Once the html is generated, we copy it inside a template literal and put it inside a js function. This function is taking parameters which corresponds to the name of the variables inside the template. As the function also returns the email body as template literal the `${variableName}` will automatically replaced. Here is an example.
+
+```ts
+export const buildFeedbackEmail = (myVariable) => {
+  const html = `<html>.... ${myVariable} ......</html>`
+  return html;
+};
+```
+
+So, everytime we need to use this template, a simple call to this function with the appropriate parameters will do the job.
 
 ## AUTHZ
 
-- 
GitLab