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:
- A SendDart API key.
- A verified domain to send from.
1. Install the SDK
npm install senddart2. 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.
SENDDART_API_KEY=mb_xxxxxxxxx4. Edit the handler function
Use the SDK client in your handler. It returns { data, error } — no try/catch needed for HTTP errors.
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.
cc, bcc, reply_to, attachments, scheduled_at — in the Send an email reference.