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
muslnode 18–226 runs
build_error
glibcnode 18–226 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.fixSet 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.fixUpgrade 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.fixEnsure 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.fixRegularly 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`).
fixUse 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.
fixFor 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.
fixImplement 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.
fixVerify 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.
fixReview 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.
Audit
Dependencies
axiosrequiredHTTP client for making API requests, frequently updated for security and performance.