Render emails server-side and send them crazy fast using Bun and React.
The best thing about Bun is its speed. It's way faster than Node.js and Deno, which makes it pretty compelling for edge computing.
Since lots of emails are sent via background jobs running in edge functions, we decided to explore how to send emails using Bun.
To get started, we will create an
index.tsx file and include a simple HTTP server that returns a "Hello World" message.
Run the local server by executing
bun index.tsx on the terminal. Once you navigate to
http://localhost:3000, you will see the message.
Now that we have this foundation, we can add the actual email functionality.
First, we import the
resend package and create a new client that will authenticate using an Resend API key.
Then, we call the
send method and return the response object. In this example, we're sending an email using the
Being able to send an email using HTML is nice, but being able to use an engine like React Email is even better.
To make things interesting, let's create a new
waitlist-email.tsx file that will render a beautiful waitlist email.
Now that we have this template, we can import it into our
index.tsx file and use it to send an email.
bun index.tsx, you should see the email being sent using React.
We're excited to see what you build with Bun and Resend.
If you want to see the full code, you can check out the GitHub repository.