Skip to content

Commit b0ccf1e

Browse files
authored
✨ Add react-email for email templates (#2421)
1 parent de53c8f commit b0ccf1e

26 files changed

Lines changed: 802 additions & 166 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
exclude: |
1414
(?x)^(
1515
frontend/src/client/.*|
16-
backend/app/email-templates/build/.*
16+
backend/app/email-templates/.*
1717
)$
1818
- id: trailing-whitespace
1919
exclude: ^frontend/src/client/.*

.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"charliermarsh.ruff",
88
"docker.docker",
99
"github.vscode-github-actions",
10-
"mjmlio.vscode-mjml",
1110
"ms-playwright.playwright",
1211
"ms-python.python",
1312
"tombi-toml.tombi"

backend/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,20 @@ If you don't want to start with the default models and want to remove them / mod
139139

140140
## Email Templates
141141

142-
The email templates are in `./backend/app/email-templates/`. Here, there are two directories: `build` and `src`. The `src` directory contains the source files that are used to build the final email templates. The `build` directory contains the final email templates that are used by the application.
142+
The email templates are written with [React Email](https://react.email) in `./packages/react-email/`. The `emails` directory holds one component per email and the `ui` directory holds the shared components (layout, heading, button, link, callout).
143143

144-
Before continuing, ensure you have the [MJML extension](https://github.com/mjmlio/vscode-mjml) installed in your VS Code.
144+
The rendered HTML in `./backend/app/email-templates/` is generated from those components, it is what the application sends, and it shouldn't be edited by hand.
145145

146-
Once you have the MJML extension installed, you can create a new email template in the `src` directory. After creating the new email template and with the `.mjml` file open in your editor, open the command palette with `Ctrl+Shift+P` and search for `MJML: Export to HTML`. This will convert the `.mjml` file to a `.html` file and now you can save it in the build directory.
146+
To preview the emails while editing them, start the dev server from the root of the project:
147+
148+
```console
149+
$ bun run email:dev
150+
```
151+
152+
Values coming from the backend are declared as Jinja placeholders in the component props, for example `username = "{{ username }}"`. The context for each email is built in `generate_*_email()` in `./backend/app/utils.py`, so a new placeholder needs to be added there too.
153+
154+
Once you are done, regenerate the templates used by the application:
155+
156+
```console
157+
$ bun run email:export
158+
```

backend/app/email-templates/build/new_account.html

Lines changed: 0 additions & 25 deletions
This file was deleted.

backend/app/email-templates/build/reset_password.html

Lines changed: 0 additions & 25 deletions
This file was deleted.

backend/app/email-templates/build/test_email.html

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)