Official Resend NPM SDK Setup
Configure the official Resend Node.js package to send requests to EmitMail.
EmitMail supports common email sending requests from the official resend Node.js package. API coverage may differ from Resend; check the features your application uses before migrating.
1. Install the Official SDK
pnpm add resend2. Configure Environment Variables
Set your API key and base URL in the environment. The SDK does not automatically read RESEND_BASE_URL; pass the base URL in the client options:
RESEND_API_KEY=em_live_your_generated_api_key
RESEND_BASE_URL=https://api.yourdomain.com
# Or for local development:
# RESEND_BASE_URL=http://localhost:4000The base URL should be the API origin expected by your deployment, for example https://api.yourdomain.com or http://localhost:4000.
3. Sending an HTML Email (Node.js / TypeScript)
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY, {
baseUrl: process.env.RESEND_BASE_URL,
});
async function sendWelcomeEmail() {
const { data, error } = await resend.emails.send({
from: 'Omkar from EmitMail <hello@yourdomain.com>',
to: ['user@example.com'],
subject: 'Welcome to EmitMail — Your workspace is ready',
html: '<p>Hi there,</p><p>Your self-hosted email engine is live with 2048-bit DKIM signing.</p>',
text: 'Hi there, Your self-hosted email engine is live with 2048-bit DKIM signing.',
replyTo: 'support@yourdomain.com',
});
if (error) {
console.error('EmitMail Error:', error);
return;
}
console.log('Email queued successfully with ID:', data?.id);
}
sendWelcomeEmail();