Formatted emails - #382
Conversation
WalkthroughThe change replaces direct Django email calls with a shared templated email helper. The backend requests rendered email content from an authenticated Next.js route, then sends multipart messages through Django. The frontend adds shared email rendering utilities and templates for verification, password reset, reset codes, and existing accounts. Email settings now use SMTP in debug mode and SES otherwise, with bridge-secret and environment documentation updates. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 519b4f66-2067-4cef-9d3d-b68073c7c351
⛔ Files ignored due to path filters (1)
frontend/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (18)
backend/.env.examplebackend/api/account/views.pybackend/api/auth/views.pybackend/api/settings.pybackend/api/utils.pybackend/requirements.txtfrontend/.env.examplefrontend/package.jsonfrontend/src/app/api/render-email/route.tsxfrontend/src/features/email/components/button.tsxfrontend/src/features/email/lib/content.tsfrontend/src/features/email/lib/render.tsxfrontend/src/features/email/templates/email-in-use.tsxfrontend/src/features/email/templates/email-verification.tsxfrontend/src/features/email/templates/password-reset-code.tsxfrontend/src/features/email/templates/password-reset.tsxfrontend/src/features/email/theme.tsfrontend/src/features/email/type.ts
This PR introduces formatted emails to the site.
Email System
A new system was established where, when sending an email from the backend, it makes a request to the frontend which renders an HTML template with the given information. It is then returned to the backend, which then sends it through whatever email service it uses to deliver to the user.
This frontend endpoint is found at
/api/render-email/, which takes a template key and other context-specific data. With this, it returns a subject, rich HTML content, and text fallback version of the email.To render HTML content, the
react-emailpackage is used for its components that are widely-compatible..envUpdatesOn the frontend, the
BASE_URLvariable was added to generate links in emails.On the backend,
SMTP_-prefixed variables were added to allow SMTP-based email sending in development.On both, the
EMAIL_BRIDGE_SECRETvariable was added for authentication for the email rendering endpoint.Local Email Testing Support
There is now the ability to use SMTP mail servers when
DEBUGis active on the backend. This allows you to use something like Mailpit to intercept messages and preview them in a browser.To enable this, set
SEND_EMAILStoTrueand fill in all the newSMTP_-prefixed credential fields in the backend.env.Email Theme
There wasn't a good way to integrate our Tailwind setup with the React Email Tailwind provider, for a variety of reasons with the most notable being extremely limited email client HTML support. In the end, I settled on duplicating our color theme and converting the values to HEX instead of OKLCH, since that's what email clients can use.
New Backend Util Function
Instead of calling
send_maildirectly, thesend_templated_emailfunction is called with the recipient email, template key, and context information to get a rendered email from the frontend and send it to the user.This has replaced all instances of
send_mailin endpoints. The one remaining insettings.pyis removed in the Discord Webhook PR.