Configuration
Learn how to configure your emails in TurboStarter.
The @turbostarter/email
package provides a simple and flexible way to send emails using various email providers. It abstracts the complexity of different email services and offers a consistent interface for sending emails with pre-defined templates.
To configure the email service, you need to set a few environment variables.
Let's break down the variables:
EMAIL_PROVIDER
- The email provider to use. Defaults to Resend.EMAIL_FROM
- The email address that emails will be sent from. Please make sure that the mail address and domain are verified in your mail provider.EMAIL_THEME
- The theme color to use for the emails. See Themes for more information.
Configuration will be validated against the schema, so you will see the error messages in the console if something is not right.
Providers
TurboStarter supports multiple email providers, each with its own configuration. Below, you'll find detailed information on how to set up and use each supported provider. Choose the one that best fits your needs and follow the instructions in the respective accordion section.
Templates
In the @turbostarter/email
package, we provide a set of pre-defined templates for you to use. You can find them in the packages/email/src/templates
directory.
When you run your development server, you will be able to preview all available templates in the browser under http://localhost:3005.
Next to the templates, you can also find some shared components that you can use in your emails. The file structure looks like this:
Feel free to add your own templates and components or modify existing ones to match them with your brand and style.
How to add a new template?
We'll go through the process of adding a new template, as it requires a few steps to make sure everything works correctly.
Define types
Let's assume that we want to add a welcome email, that new users will receive after signing up.
We'll start with defining new template type in packages/email/src/types/templates.ts
file:
Also, we would need to add types for variables that we'll pass to the template (if any), in our case it will be just a name
of the user:
By doing this, we ensure that payload passed to the template will have all required properties and we won't end up with an email that tells your user "Hey, undefined!".
Create template
Next up, we need to create a file with the template itself. We'll create an welcome.tsx
file in packages/email/src/templates
directory.
As you can see, by defining appropriate types for the template, we can safely use the variables as a props in the template.
To learn more about supported components, please refer to the React Email documentation.
Register template
We have to register the template in the main entrypoint of the templates in packages/email/src/templates/index.ts
file:
That way, it will be available in the sendEmail
function, enabling us to send it from the server-side of your application.
Learn more about sending emails in the dedicated section.
Et voilà! You've just added a new email template to your application 🎉
Last updated on