Registry / communication / node-mailjet

node-mailjet

JSON →
library6.0.11jsnpmunverified

The `node-mailjet` library is the official JavaScript SDK for interacting with the Mailjet Email and SMS APIs. Currently at stable version 6.0.11, the package demonstrates an active maintenance schedule with frequent patch releases addressing bug fixes and critical dependency updates, such as those for `axios` to mitigate security vulnerabilities. While major version releases are less frequent, the library ensures ongoing compatibility and performance. A key differentiator is its versatility, allowing usage in both Node.js server-side environments and client-side browser applications, though browser usage necessitates a proxy due to Cross-Origin Resource Sharing (CORS) limitations and careful handling of API keys. It offers comprehensive TypeScript typings out-of-the-box, simplifying development and improving type safety. The SDK facilitates sending emails, managing contacts, and interacting with other Mailjet API endpoints, providing a robust interface for transactional and marketing communication.

npm install node-mailjet
INSTALL
IMPORT
SIG · NODE-MAILJET
N
node-mailjet
communicationjavascriptv6.0.11
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Mailjet
const Mailjet = require('node-mailjet');
import Mailjet from 'node-mailjet';
For CommonJS environments, `require()` directly returns the `Mailjet` class constructor.
Client
import { Client } from 'node-mailjet';
const { Client } = require('node-mailjet');
For ES Modules and TypeScript, the main Mailjet client class is exported as `Client`.
SendParams
import type { SendParams } from 'node-mailjet';
import { SendParams } from 'node-mailjet'; // If only type is needed
TypeScript users should import types using `import type` for clarity and bundler optimization.

Demonstrates how to initialize the Mailjet client and send a simple transactional email using the v3.1 Send API.

import { Client } from 'node-mailjet'; const mailjet = new Client({ apiKey: process.env.MJ_APIKEY_PUBLIC ?? 'your-api-key', apiSecret: process.env.MJ_APIKEY_PRIVATE ?? 'your-api-secret' }); async function sendExampleEmail() { try { const request = mailjet .post('send', { version: 'v3.1' }) .request({ Messages: [ { From: { Email: 'sender@example.com', Name: 'Your Name' }, To: [ { Email: 'recipient@example.com', Name: 'Recipient Name' } ], Subject: 'Greetings from Mailjet!', TextPart: 'My first Mailjet email', HTMLPart: '<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!', CustomID: 'AppGettingStartedTest' } ] }); const result = await request; console.log('Email sent successfully:', result.body.Messages[0].Status); } catch (error: any) { console.error('Failed to send email:', error.statusCode, error.response.body); } } sendExampleEmail();
Debug
Known issues
gotchaWhen using `node-mailjet` in a browser environment, a proxy server is required to bypass CORS (Cross-Origin Resource Sharing) limitations. Direct API calls from the browser will be blocked.
fix
Set up a server-side proxy to route Mailjet API requests, and ensure your private API keys are never exposed in client-side code.
affects: >=1.0.0
breakingThe library officially supports Node.js versions `>= v12.x`. Using older Node.js versions may lead to unexpected behavior or runtime errors.
fix
Upgrade your Node.js environment to version 12 or newer to ensure full compatibility and access to modern language features.
affects: <6.0.0 (based on package.json engines)
gotchaMailjet's Email API uses `apiKey` and `apiSecret` for authentication, while the SMS API uses a `apiToken`. Mixing these authentication methods will result in authentication failures.
fix
Ensure you are using the correct authentication credentials for the specific Mailjet API you are interacting with (Email vs. SMS).
affects: >=1.0.0
gotchaThe `node-mailjet` library frequently updates its `axios` dependency due to security vulnerabilities identified in `axios` itself (e.g., `GHSA-jchw-25xp-jwwc`). Failure to keep `node-mailjet` updated can expose your application to these underlying HTTP client vulnerabilities.
fix
Regularly update `node-mailjet` to its latest version using `npm install node-mailjet@latest` to ensure you receive critical security patches for its dependencies.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use `require('node-mailjet')` in an environment configured for ES Modules (e.g., in a `.mjs` file or when `type: "module"` is set in `package.json`).
fix
Use ESM import syntax: `import { Client } from 'node-mailjet';`.
TypeError: Mailjet is not a constructor
Incorrectly importing the Mailjet client. This often happens when mixing CommonJS `require` with ES Module named imports, or vice-versa, or attempting to call `new` on a non-constructor.
fix
For CommonJS, use `const Mailjet = require('node-mailjet'); new Mailjet(...)`. For ES Modules/TypeScript, use `import { Client } from 'node-mailjet'; new Client(...)`.
Access to fetch at 'https://api.mailjet.com/v3.1/send' from origin '...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Direct API calls to Mailjet from a web browser without an intermediary proxy server. Mailjet's API does not allow direct cross-origin requests from browsers.
fix
Implement a server-side proxy that forwards requests to Mailjet's API. Your frontend code should call your proxy, not Mailjet directly.
Error: Request failed with status code 401
Invalid or missing Mailjet API public/secret keys or API token for the SMS API.
fix
Verify your `MJ_APIKEY_PUBLIC`, `MJ_APIKEY_PRIVATE`, or `MJ_API_TOKEN` environment variables are correctly set and correspond to active Mailjet credentials. Ensure the correct authentication method is used for the API endpoint (Email vs. SMS).
Error: Missing required parameter: From.Email
The request payload sent to the Mailjet API is missing a required field, such as the sender's email address in an email send request.
fix
Review the Mailjet API documentation for the specific endpoint you are calling and ensure all mandatory fields are present and correctly formatted in your request body.
Upgrade
Version history
6.0.11latest on npm
Audit
Dependencies
axiosrequiredHTTP client for making API requests, frequently updated for security and performance.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources