The MailerSend Node.js SDK provides a comprehensive programmatic interface for interacting with the MailerSend API, enabling developers to efficiently send transactional and marketing emails, manage SMS campaigns, configure domains, set up webhooks, utilize templates, and track analytics data. The current stable version is `2.8.0`, released with a consistent and active development cadence, typically seeing updates monthly or bi-monthly. This commitment ensures the library remains up-to-date with API changes and introduces new features regularly. Key differentiators include its focus on high email deliverability, an intuitive API design that simplifies complex email operations, and built-in integrations for streamlined workflows. The SDK fully supports both email and SMS functionalities and ships with comprehensive TypeScript types, enhancing developer experience through improved type safety and autocompletion.
npm install mailersendVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the MailerSend client and send a basic HTML email using environment variables for configuration. It covers setting up sender and recipient details and handling potential errors.
Consult the MailerSend V2 documentation for updated API methods and class structures. The project README explicitly links to the V1 documentation for reference during migration.
Review the MailerSend API documentation for the current recommended approach to email personalization, which typically involves using `setPersonalization` on `EmailParams` with an array of objects.
Always use environment variables (e.g., `process.env.MAILERSEND_API_TOKEN`), a secrets manager, or a `.env` file (for local development) to manage your API key securely. Do not hardcode or commit API keys.
Use a named import for the `MailerSend` class: `import { MailerSend } from 'mailersend';`Verify that your `MAILERSEND_API_TOKEN` environment variable (or wherever you've configured it) is correctly set to a valid MailerSend API key with the necessary permissions to send emails. Ensure there are no typos or leading/trailing spaces.
Ensure that all mandatory fields are set on your `EmailParams` instance. For example, `emailParams.setFrom(sender)`, `emailParams.setTo(recipients)`, and `emailParams.setSubject('...')` must be called with valid data.No dependency data recorded yet.