Send Emails with MailerSend
MailerSend is a transactional email API. We will use it to send emails from our NextJS app. MailerSend allows us to send up to 3000 emails per month for free.
Before we start, create a MailerSend account.
Configure you domain
Add you domain to MailerSend. We need this in order to send emails from something@yourdomain.com.
Verify your domain. You can do this by adding a TXT record to your DNS setting like MailerSend suggests.
Create a new API key
Click "Manage" near your domain. Then click "Generate new token". We will need this token in our NextJS project.
Add the token to your .env.local file:
MAILERSEND_KEY=YOUR_TOKEN
Configure email templates
In the SupaLaunch project, open /src/lib/emails
folder. In the email-templates.ts
file you will find the template we used to send you the welcome email. Add your template to the list.
Send emails via API
In order to send emails, there is a function called sendEmail
in /src/lib/emails/send-email.ts
. This function takes the email address and the template as parameters. It will send the email to the email address using the template you specified.
You can call this function from any API route inside your project (see /src/api/emails
as an example).