SimpleNS LogoDocs
Official Plugins

Resend Plugin

Send emails via Resend API with automatic image handling


What is Resend Plugin

The @simplens/resend plugin enables email delivery through the Resend API. Resend is a modern email API built for developers, offering excellent deliverability and a simple integration experience.

How It Works

This plugin creates a Resend client and handles email delivery with advanced features:

  1. The plugin receives the notification payload
  2. Replaces any template variables in subject and HTML content
  3. Automatically extracts base64 images and converts them to CID attachments
  4. Sends the email via Resend API

Resend free tier allows 100 emails/day. Pro plans offer 5,000+ emails/day. Check Resend Pricing for details.


Installation

Generate the plugin configuration using the @simplens/config-gen CLI:

# Generate a new config file with the resend plugin
npx @simplens/config-gen generate @simplens/resend

# Or add to an existing config file
npx @simplens/config-gen gen @simplens/resend -c simplens.config.yaml

SimpleNS automatically installs plugins on startup based on your simplens.config.yaml. See the Plugin Installation Guide for more details.


Configuration

Add the plugin to your simplens.config.yaml if you used Config-first method from Plugin Installation Guide:

simplens.config.yaml
providers:
  - package: "@simplens/resend"
    id: email-resend
    credentials:
      RESEND_API_KEY: ${RESEND_API_KEY}
      FROM_EMAIL: ${FROM_EMAIL}
    options:
      rateLimit:
        maxTokens: 100
        refillRate: 100
        refillInterval: day

channels:
  email:
    default: "email-resend"

Required Credentials

KeyDescription
RESEND_API_KEYYour Resend API key (get one here)
FROM_EMAILVerified sender email address (verify domain)

Rate Limiting Options

KeyDefaultDescription
maxTokens100Max emails in bucket
refillRate100Tokens refilled per interval
refillIntervaldayInterval: second, minute, hour, or day
PlanSuggested Config
FreemaxTokens: 100, refillRate: 100, refillInterval: day
PromaxTokens: 5000, refillRate: 5000, refillInterval: day

Resend API Key Setup

Create a Resend Account

Go to resend.com and sign up for a free account.

Get Your API Key

Navigate to API Keys and create a new API key.

Verify Your Domain

Go to Domains and add your sending domain. Follow the DNS verification steps.

Configure Your Plugin

Set RESEND_API_KEY and FROM_EMAIL in your environment variables.

You must verify your domain in Resend before sending emails. Without verification, you can only send to your own email address.


Environment Variables

.env
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxxxxxxx
FROM_EMAIL=notifications@yourdomain.com

Notification Payload

  • You can easily get and configure this request payload from Payload Studio in Admin Dashboard
{
  "request_id": "uuid-v4",
  "client_id": "uuid-v4",
  "channel": "email",
  "recipient": {
    "user_id": "user-123",
    "email": "recipient@example.com"
  },
  "content": {
    "subject": "Welcome {{name}}!",
    "html": "<h1>Hello {{name}}</h1><p>Your order #{{order_id}} is confirmed.</p>"
  },
  "variables": {
    "name": "John",
    "order_id": "12345"
  }
}

Notification Schema

FieldTypeRequiredDescription
channel'email'Must be 'email'
recipient.user_idstringUser identifier
recipient.emailstringValid email address
content.subjectstringEmail subject line
content.htmlstringHTML content (must contain at least one tag)
variablesobjectTemplate variables for replacement

Features

FeatureDescription
HTML Email SupportSend rich HTML emails
Template VariablesSupports {{key}}, ${key}, {key}, $key syntax
Auto Image ExtractionConverts base64 images to CID attachments automatically
Rate LimitingConfigurable token bucket with refill intervals
Smart RetryClassifies errors as retryable or non-retryable
TypeScript SupportFull TypeScript definitions included

Template Variable Syntax

The plugin supports multiple template variable formats:

FormatExample
Handlebars{{variable}}
ES6 Template${variable}
Simple Brace{variable}
Shell/PHP$variable

Unmatched variables are left as-is in the output, allowing for safe partial replacements.


Base64 Image Handling

The plugin automatically detects base64-encoded images in your HTML content and converts them to CID (Content-ID) attachments. This improves email deliverability as many email clients block inline base64 images.

Before processing:

<img src="data:image/png;base64,iVBORw0KGgo..." alt="Logo">

After processing:

<img src="cid:embedded-image-0-1234567890" alt="Logo">

The base64 data is automatically attached to the email as a proper image attachment.

On this page