Luigi
Published on

Sending emails using Resend

Introduction

In this guide, I’ll walk you through the steps to set up your SMTP integration using the Resend Node.js SDK. By the end, you’ll have everything you need to start sending emails through your domain via Resend.

Prerequisites

Before diving into the SMTP configuration, ensure you have completed the following steps:

  1. Create an API Key

    • Sign up or log in to your Resend account.
    • Navigate to the API section and generate a new API key. This key will be essential for authenticating your requests.
  2. Verify Your Domain

    Follow Resend's domain verification process to ensure you can send emails from your domain. This typically involves adding DNS records provided by Resend to your domain's DNS settings.

SMTP Credentials

When setting up your SMTP integration, you will need to use specific credentials provided by Resend. These credentials are essential for establishing a connection between your email client or application and the Resend SMTP server.

Here are the SMTP credentials you'll need:

  • Host: smtp.resend.com
  • Port: 25, 465, 587, 2465, or 2587
  • Username: resend
  • Password: YOUR_API_KEY

Understanding SMTP ports

Ports help to instruct the type of security you want to use in your SMTP connection.

  • For a SSL connection, use port 465 or 2465.
  • For an unencrypted or a TLS connection, use port 25, 587, or 2587.

resend dashboard

Code sample

import { Resend } from 'resend';

const resend = new Resend('YOUR_API_KEY');

async function sendEmail() {
  try {
    const { data, error } = await resend.emails.send({
      from: 'Acme <onboarding@email.com>',
      to: ['delivered@email.come'],
      subject: 'Hello World',
      html: '<p>Sent</p>',
    });

    if (error) {
      throw new Error(error.message);
    }

    console.log('Email sent successfully:', data);
  } catch (err) {
    console.error('Error while sending email:', err);
  }
}

sendEmail();

Let me know what your thoughts are about this article hi[at]luigimorel.com. Cheers!

© 2022 - 2024 Luigi Morel. All rights reserved.