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.
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.
- macOS
- Linux
- Windows
brew install superfaceai/cli/superface
npm install -g @superfaceai/cli@latest
npm install -g @superfaceai/cli@latest
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"
Turn the Comlink into code
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.
- Node.js
- Python
superface map resend email-communication/email-sending
superface map resend email-communication/email-sending python
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 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.
- Node.js
- Python
{
to: 'youremail@yourdomain.com',
from: 'onboarding@resend.dev',
subject: 'Hello, World!',
html: '<p>Hello, World!</p>',
text: 'Hello, World!',
},
{
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.
- Node.js
- Python
superface execute resend email-communication/email-sending
superface execute resend email-communication/email-sending python
If everything is successful you should see output similar to the response below:
RESULT: {
"id": "9d5c7482-d197-406f-b8f9-9a4c0cb7d5f9"
}