Docs Get key
All server guides
Email Providers

Send asynchronous email with MailerSend's SDK

Build an EmailParams message with MailerSend's official client and retain asynchronous message correlation for delivery checks.

Reviewed

Install the documented JavaScript client with npm install mailersend. Supply MAILERSEND_API_KEY, APP_FROM, and TEST_TO through secure backend configuration. Approve the real sender and controlled recipient before running this live send:

import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
for (const key of ["MAILERSEND_API_KEY", "APP_FROM", "TEST_TO"]) {
  if (!process.env[key]) throw new Error(`Missing ${key}`);
}
const client = new MailerSend({ apiKey: process.env.MAILERSEND_API_KEY });
const message = new EmailParams()
  .setFrom(new Sender(process.env.APP_FROM))
  .setTo([new Recipient(process.env.TEST_TO)])
  .setSubject("MailerSend controlled test")
  .setText("A message from the approved application sender.");
await client.email.send(message);

Retain asynchronous correlation

The sending reference describes asynchronous acceptance and the x-message-id used for subsequent status inspection. Capture that identifier using the response/header access documented for your installed SDK version, and associate it with a previously persisted send intent.

Check provider activity and the controlled inbox before expanding traffic. A 202 acceptance is not a final delivery result. Follow applicable activity/webhook APIs for ongoing feedback instead of an unbounded polling loop.

Validation, permission, or unverified-domain failures need specific fixes. If the connection times out after submission, investigate the message record before repeating it or falling back to another sender. MailKite is a separate transport with its own SDK/domain verification, not a shared bearer-token endpoint.