Resend: sending email for beginners got even easier

plabonkumarsaha

Plabon Kumar saha

Posted on March 24, 2024

Resend: sending email for beginners got even easier

we have always been using Sendgrid for configuring and sending emails. But I found an even easier solution. Literally within some lines of code, you’ll be able to set up emails. In this discussion, I’ll showcase how it is better than Sendgrid and how can you easily set it up in your code.

**

Why is it better?

**

  1. Modern simpler functionality and easy to use.
  2. Pricing is compromised (even though the SendGrid fee tire has a larger capacity)
  3. Simpler analytics

now let’s learn how to implement it in node js.

1.Go to Resend Website and register. You’ll get a page like this

Image description

  1. Now add a domain and add the configure value in your DNS record.

Image description
now you’ll be able to use your domain name’s email as the sender email such as contact@domain.

  1. Now add them to your node project add dependency
pnpm add resend

Enter fullscreen mode Exit fullscreen mode

Then add your RESEND_KEY in your env file. During calling the function call it like the following. You’ll get the key from API Keys sub-section.

import { Resend } from "resend";
app.get("/send-email", async (req: Request, res: Response) => {
htmlScript="<strong>it works!</strong>";
  const resend = new Resend(process.env.RESEND_KEY);
  const { data, error } = await resend.emails.send({
   from: process.env.SEND_EMAIL,
   to: ['receiver@gmail.com'],
   subject: "Testing Resend email platform",
   html: htmlScript,
    });
  if (error) {
    return res.status(400).json({ error });
  }

  res.status(200).json({ data });
});
Enter fullscreen mode Exit fullscreen mode

And would you believe it! This is done. Now each time your endpoint is called you’ll get logs like the following.

Image description

Image description
I hope this is helpful to you. Happy implementing.

💖 💪 🙅 🚩
plabonkumarsaha
Plabon Kumar saha

Posted on March 24, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related