AWS Lambda
Send your first email from an AWS Lambda function using the mailblastr SDK.
Send your first email from an AWS Lambda function using the mailblastr 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 MailBlastr API key.
- A verified domain to send from.
1. Install the SDK
npm install mailblastr2. 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 MAILBLASTR_API_KEY with your key. Reading it from the environment keeps the secret out of source.
MAILBLASTR_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 { MailBlastr } from 'mailblastr';
const mb = new MailBlastr(process.env.MAILBLASTR_API_KEY);
export const handler = async (event) => {
const { data, error } = await mb.emails.send({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@example.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, tags, scheduled_at — in the Send an email reference.