Quick setup examples

AWS Lambda

Send your first email from an AWS Lambda function using the senddart SDK.

Send your first email from an AWS Lambda function using the senddart Node SDK. Bundle the SDK into your Lambda deployment package with your preferred bundler (esbuild, webpack, etc.) or a Lambda Layer.

Prerequisites

Before you start, you will need:

1. Install the SDK

npm install senddart

2. Create an AWS Lambda function

Go to aws.amazon.com and create a new Lambda function using the Node.js 20.x (or later) runtime.

3. Store your API key

Under the function's Configuration → Environment variables, add SENDDART_API_KEY with your key. Reading it from the environment keeps the secret out of source.

Environment variable
SENDDART_API_KEY=mb_xxxxxxxxx

4. Edit the handler function

Use the SDK client in your handler. It returns { data, error } — no try/catch needed for HTTP errors.

index.mjs
import { SendDart } from 'senddart';

const mb = new SendDart(process.env.SENDDART_API_KEY);

export const handler = async (event) => {
  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,
    body: JSON.stringify(error ? { error } : { data }),
  };
};

5. Deploy and send email

Click Deploy, then Test at the top of the screen. A successful run returns the created email's id.

See the full request body — cc, bcc, reply_to, attachments, scheduled_at — in the Send an email reference.