Registry / messaging / nodemailer-mailgun-transport

nodemailer-mailgun-transport

JSON →
library2.1.5jsnpmunverified

A transport plugin for Nodemailer that sends emails via Mailgun's REST API instead of SMTP. Version 2.1.5 is stable but receives infrequent updates. It wraps the mailgun-js library to provide a drop-in transport for Nodemailer, enabling easy switching between email providers. Key differentiator: uses HTTP API, avoiding SMTP port blocks and providing better deliverability analytics. Alternative to nodemailer's built-in SMTP transport or other HTTP transports like SendGrid.

npm install nodemailer-mailgun-transport
INSTALL
IMPORT
SIG · NODEMAILER-MAILGUN
N
nodemailer-mailgun-transport
messagingjavascriptv2.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import mg from 'nodemailer-mailgun-transport'
const mg = require('nodemailer-mailgun-transport').default
ESM default import; CommonJS users use require. No named exports.
default
const mg = require('nodemailer-mailgun-transport')
const { mg } = require('nodemailer-mailgun-transport')
CommonJS require returns the function directly, not an object.
NodemailerMailgunTransport
import mg from 'nodemailer-mailgun-transport'
import { NodemailerMailgunTransport } from 'nodemailer-mailgun-transport'
No named export; only default export.

Setup Nodemailer with Mailgun transport using API key and domain.

const nodemailer = require('nodemailer'); const mg = require('nodemailer-mailgun-transport'); const auth = { auth: { api_key: process.env.MAILGUN_API_KEY || 'key-1234123412341234', domain: process.env.MAILGUN_DOMAIN || 'example.com' } }; const nodemailerMailgun = nodemailer.createTransport(mg(auth)); nodemailerMailgun.sendMail({ from: 'sender@example.com', to: 'recipient@example.com', subject: 'Hello', text: 'Testing Mailgun transport!' }, (err, info) => { if (err) { console.log(`Error: ${err}`); } else { console.log(`Response: ${info}`); } });
Debug
Known issues
breakingmailgun-js v0.22.x removed callback support; this package may not handle promises correctly.
fix
Use async/await or update to a newer version that supports promises.
affects: >=2.1.0
deprecatedmailgun-js is deprecated; consider using the official @mailgun/mailgun-js package.
fix
Switch to @mailgun/mailgun-js or use fetch directly.
affects: >=1.0.0
gotchaThe auth object must have both api_key and domain, but domain is not validated; using wrong domain causes silent failures.
fix
Double-check the domain matches your Mailgun sending domain.
affects: >=0.1.0
gotchaIf you omit the api_key, the transport fails with 'auth.api_key is missing' error.
fix
Always provide api_key in auth object.
affects: >=0.1.0
deprecatedThe 'mg' function originally accepted options object directly; in v2+, it must be wrapped in {auth: {api_key, domain}}.
fix
Use {auth: {api_key: 'key', domain: 'domain'}} format.
affects: >=2.0.0
Errors
Common errors & fixes
auth.api_key is missing
No api_key provided in auth object.
fix
Add api_key: 'your-key' to the auth object.
Cannot find module 'mailgun-js'
mailgun-js peer dependency not installed.
fix
Run npm install mailgun-js.
TypeError: mg is not a function
Importing incorrectly (e.g., destructuring a named export).
fix
Use const mg = require('nodemailer-mailgun-transport') or import mg from '...'.
Error: Invalid credentials
Wrong API key or domain.
fix
Verify MAILGUN_API_KEY and MAILGUN_DOMAIN environment variables.
Upgrade
Version history
2.1.5latest on npm
Audit
Dependencies
nodemailerrequiredThis is a transport plugin for nodemailer; nodemailer must be installed separately.
mailgun-jsrequiredUnderlying library for Mailgun API calls; installed as a dependency of this package.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
2
Amazon
1
Resources
nodemailer-mailgun-transport — npm install nodemailer-mailgun-transport · libregistry