Quick setup examples
RedwoodJS
Send your first email from a RedwoodJS serverless function using the senddart SDK.
Send your first email from a RedwoodJS app using the senddart Node SDK. Install it with npm install senddart, then import SendDart and call mb.emails.send(). Redwood serverless functions live in the api side, so the call (and your key) stay on the server.
Prerequisites
- A SendDart API key.
- A verified domain to send from.
1. Install the SDK
yarn workspace api add senddart2. Add your API key
Add your key to the project .env. Redwood loads it into the api side automatically.
.env
SENDDART_API_KEY=mb_xxxxxxxxx3. Generate a function
Scaffold a serverless function on the api side.
yarn rw g function send4. Send email from the function
Edit the generated handler to use the SDK.
api/src/functions/send/send.ts
import type { APIGatewayEvent, Context } from 'aws-lambda';
import { SendDart } from 'senddart';
const mb = new SendDart(process.env.SENDDART_API_KEY!);
export const handler = async (_event: APIGatewayEvent, _context: Context) => {
const { data, error } = await mb.emails.send({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@test.senddart.com'],
subject: 'hello world',
html: '<strong>it works!</strong>',
});
return {
statusCode: error ? 500 : 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(error ? { error } : { data }),
};
};A successful call returns the created email's
id. See the full request body in the Send an email reference.