Photo by Brett Jordan on Unsplash
Sending Emails using Resend
Send Emails to your users using Resend in NodeJS in just a couple of few steps.
Resend is an SMTP email service that lets you send emails from your domain. It’s easy to use and has a lot of features that make it a good choice for businesses of all sizes.
Here is how you can send an email using Resend in NodeJS.
Create a Resend account here https://resend.com/ and add your custom domain. You can still use their test domain for test and development.
Folder Overview
Server.js
is the entry point for our app.app.js
configures our application and dependencies for developmentrouter
defines API endpoints for our application.controllers
contain an async function which will be called once our app hits an endpoint.config.env
containsAPI KEYS
for Resend Configurations.
Create a
NodeJS serve
r usingexpress
Create
app.js
file and make app configurationsIncludes setting up the routing for our email endpoint
Adding Morgan for
logging
and setting up ourmiddleware
.
Configuring routing
Creating a
POST
route that will be responsible for sending our email to a user.
Creating our controller function to send our email using Resend
Install Resend npm package -
npm i resend
Create a resend client using your generated
API KEY
new resend.Resend(process.env.RESEND_PASSKEY);
Get the data from the
res. body
such as from(Your custom domain), to, subject and the content of the email.Make the send email using your Resend client to send email.
Ensure to catch errors💥
Email will be sent to the user's inbox and Resend will show you on your Dashboard.
Github Repository - github.com/Karumaidoi/Resend-Email