Skip to main content

Resend

In this example, we will show you how you can get started working with the Resend email API to produce a working use case that allows you to send an email from an application.

Before you start

You'll need a Resend API token. Find out how to set that up in the Resend documentation.

Install & Authorize Superface

The Superface CLI provides all the tooling needed to author the Comlinks for your integration.

Install with Homebrew
brew install superfaceai/cli/superface

If you don't have a Superface account already, you can sign up here. You can use your account to authenticate the CLI.

superface login

Prepare the documentation

Resend have an OAS version of their API, you can use this as the documentation source.

superface prepare https://raw.githubusercontent.com/resendlabs/resend-openapi/main/resend.yaml

Once the documentation has been indexed, you can create a profile for the use case you want to achieve.

superface new resend "send an email"

To turn the Comlink profile into runnable code in either Node.js or Python, use the following command and include the name of the provider and a use case profile you want to work with.

superface map resend email-communication/email-sending

Set up your inputs

In order to send an email correctly, you will need to modify the boilerplate code from the Resend documentation so it contains a real email address. From the superface folder, open email-communication.email-sending.resend.mjs (or .py if you created Python files) and modify the object in the usecase.perform() function.

Resend has sending restrictions

Resend only allows test emails to be sent to the email address registered on the account. The to value in the example below must be set to this.

email-communication.email-sending.resend.mjs
{
to: 'youremail@yourdomain.com',
from: 'onboarding@resend.dev',
subject: 'Hello, World!',
html: '<p>Hello, World!</p>',
text: 'Hello, World!',
},

Add your API token

If you don't already have your Resend API token in your environment, you can add it to your .env file as RESEND_TOKEN=<your-resend-token>".

You can create a new API Token from the API Keys section of your Resend Account. Please ensure the Permission is set for Sending Access.

Test it

The resulting code from the previous step is added to the superface folder in your project. To test it you can use the execute command.

superface execute resend email-communication/email-sending

If everything is successful you should see output similar to the response below:

RESULT: {
"id": "9d5c7482-d197-406f-b8f9-9a4c0cb7d5f9"
}