bởi Naima B.

A universal JavaScript SDK for the Mailgun email API, supporting Node.js and browser environments. Send messages, manage domains, suppressions, webhooks, mailing lists, and more.
This block is the full TypeScript source of the official mailgun.js SDK, which wraps the Mailgun REST API for sending transactional email, managing domains, suppressions, mailing lists, webhooks, and more. It targets Node.js 18+ backends and any bundler-capable frontend (with a proxy). Buyers integrating email delivery, bounce management, or domain administration into a Node.js/TypeScript project are the primary audience.
source/index.ts - Main entry point; exports the Mailgun class used to bootstrap the client.source/definitions.ts - Shared type definitions and constants used across the SDK.source/Enums/ - TypeScript enums: Resolution, SuppressionModels, WebhooksIds, YesNo.source/Interfaces/ - All TypeScript interfaces for request/response shapes (domains, events, messages, suppressions, etc.).source/Types/ - Composite type aliases used in method signatures.source/Classes/MailgunClient.ts - Top-level client aggregating all sub-clients.source/Classes/Messages.ts - Email sending logic.source/Classes/Domains/ - Domain CRUD, credentials, tracking, templates, tags, and keys.source/Classes/Suppressions/ - Bounce, complaint, unsubscribe, and whitelist suppression management.source/Classes/MailingLists/ - Mailing list and member management.source/Classes/Events.ts - Event polling and filtering.source/Classes/Webhooks.ts - Webhook CRUD.source/Classes/Stats/ - Statistics retrieval and container helpers.source/Classes/Validations/ - Single and bulk email validation.source/Classes/InboxPlacements/ - Inbox placement testing, seed lists, results, and sharing.source/Classes/Metrics/ - Account and domain metrics client.source/Classes/Logs/ - Log retrieval client.source/Classes/DKIM/ - DKIM key management.source/Classes/BounceClassification/ - Bounce classification lookup.source/Classes/Tags/ - Tag management.source/Classes/IPs.ts - IP address management.Khởi chạy sandbox cách ly và chạy phía máy chủ — không cần cài đặt cục bộ.
Tetrees AI Review cho phiên bản này
This TypeScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Quy trình avcp-2026-08-04.1 · SHA-256 15504640e48fce20…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Đã đánh giá 4 thg 8, 2026
Đưa sản phẩm này thẳng vào AI IDE, trình tạo web hoặc cloud IDE của bạn.
Kết nối Tetrees với AI IDE tương thích để liệt kê sản phẩm bạn sở hữu và nhận ZIP đã xác minh mà không cấp quyền tải lên của người bán.
Chưa có đánh giá.
Sign in to join the discussion
Loading discussion…
source/Classes/IPPools.ts - IP pool management.source/Classes/Routes.ts - Routing rule management.source/Classes/Subaccounts.ts - Subaccount management.source/Classes/common/ - Shared utilities: HTTP request layer, FormData builder, error handling, pagination, attachment handler.npm install axios base-64 url-join
npm install --save-dev typescript @types/node
No native build steps, pod installs, or Android linking are required. This is a pure Node.js/browser library.
Copy the source/ directory into your project, for example at src/mailgun/.
Ensure your tsconfig.json targets ES2020 or later and has module resolution set to node16 or bundler:
{
"compilerOptions": {
"target": "ES2020",
"module": "Node16",
"moduleResolution": "node16",
"esModuleInterop": true,
"strict": true,
"paths": {
"mailgun-sdk/*": ["./src/mailgun/*"]
}
}
}
.env or your secrets manager):MAILGUN_API_KEY=your-private-api-key
MAILGUN_DOMAIN=mg.yourdomain.com
# Optional: for EU infrastructure
MAILGUN_API_URL=https://api.eu.mailgun.net
Import and instantiate the client (see examples below). The FormData constructor argument accepts the built-in global FormData (Node 18+) or the form-data npm package.
All .js extension imports inside the source files are intentional for ESM compatibility. If you use CommonJS ("module": "CommonJS"), you may need a bundler step or adjust the import paths.
Mailgun (default export from source/index.ts)import Mailgun from './src/mailgun/index.js';
class Mailgun {
constructor(FormData: InputFormData);
client(options: MailgunClientOptions): IMailgunClient;
static get default(): typeof Mailgun;
}
The root factory class. Instantiate once per process with a FormData implementation, then call .client() with your API credentials. The static get default accessor enables import('mailgun.js').then(m => new m.default(FormData)) dynamic import patterns.
MailgunClientOptions (from source/Types/index.ts)interface MailgunClientOptions {
username: string; // always 'api'
key: string; // your Mailgun private API key
url?: string; // defaults to https://api.mailgun.net; use EU URL if needed
timeout?: number;
proxy?: { protocol: string; host: string; port: number };
}
Passed to mailgun.client(options). Use url: 'https://api.eu.mailgun.net' for EU-region sending domains. Proxy config is useful for browser environments routing through a backend proxy.
IMailgunClient (from source/Interfaces/MailgunClient/index.ts)interface IMailgunClient {
messages: /* MessagesClient */;
domains: /* DomainsClient */;
events: /* EventsClient */;
suppressions:/* SuppressionsClient */;
webhooks: /* WebhooksClient */;
lists: /* MailingListsClient */;
validate: /* ValidateClient */;
stats: /* StatsClient */;
metrics: /* MetricsClient */;
logs: /* LogsClient */;
// ...additional sub-clients
}
The unified client returned by mailgun.client(). Each property is a namespaced sub-client. Call methods directly: mg.messages.create(domain, data), mg.suppressions.list(domain, model), etc.
source/Enums/index.ts)import { Resolution, SuppressionModels, WebhooksIds, YesNo } from './src/mailgun/Enums/index.js';
Resolution.HOUR // 'hour'
Resolution.DAY // 'day'
Resolution.MONTH // 'month'
SuppressionModels.BOUNCES // 'bounces'
SuppressionModels.COMPLAINTS // 'complaints'
SuppressionModels.UNSUBSCRIBES // 'unsubscribes'
SuppressionModels.WHITELISTS // 'whitelists'
WebhooksIds.CLICKED // 'clicked'
WebhooksIds.PERMANENT_FAIL // 'permanent_fail'
Use these enums instead of raw strings to avoid typos in API calls and to get IDE autocomplete.
Basic message delivery to a single recipient using the messages sub-client.
import Mailgun from './src/mailgun/index.js';
const mailgun = new Mailgun(FormData);
const mg = mailgun.client({
username: 'api',
key: process.env.MAILGUN_API_KEY!,
url: process.env.MAILGUN_API_URL, // omit for US
});
async function sendEmail() {
const domain = process.env.MAILGUN_DOMAIN!;
const result = await mg.messages.create(domain, {
from: `Sender <mailgun@${domain}>`,
to: ['recipient@example.com'],
subject: 'Hello from Mailgun SDK',
text: 'This is a test message.',
html: '<p>This is a <b>test</b> message.</p>',
});
console.log('Message queued:', result.id);
}
sendEmail().catch(console.error);
Retrieve the bounce suppression list and remove a specific address.
import Mailgun from './src/mailgun/index.js';
import { SuppressionModels } from './src/mailgun/Enums/index.js';
const mg = new Mailgun(FormData).client({
username: 'api',
key: process.env.MAILGUN_API_KEY!,
});
async function manageBounces() {
const domain = process.env.MAILGUN_DOMAIN!;
// List bounces
const bounces = await mg.suppressions.list(domain, SuppressionModels.BOUNCES);
console.log('Bounced addresses:', bounces.items);
// Delete a specific bounce
const address = 'bad@example.com';
await mg.suppressions.destroy(domain, SuppressionModels.BOUNCES, address);
console.log(`Removed ${address} from bounce list`);
}
manageBounces().catch(console.error);
Poll the events API for delivered messages within a time window.
import Mailgun from './src/mailgun/index.js';
import { Resolution } from './src/mailgun/Enums/index.js';
const mg = new Mailgun(FormData).client({
username: 'api',
key: process.env.MAILGUN_API_KEY!,
});
async function fetchDeliveredEvents() {
const domain = process.env.MAILGUN_DOMAIN!;
const page = await mg.events.get(domain, {
event: 'delivered',
limit: 25,
});
for (const event of page.items) {
console.log(event.timestamp, event.recipient);
}
// Navigate to the next page if available
if (page.pages?.next?.url) {
const next = await mg.events.get(domain, { page: 'next' });
console.log('Next page count:', next.items.length);
}
}
fetchDeliveredEvents().catch(console.error);
source/index.ts - Exports the Mailgun class; the only entry point buyers need to import.source/definitions.ts - Internal constant definitions and shared primitives referenced throughout the codebase.source/Enums/index.ts - Barrel that exports all SDK enums (Resolution, SuppressionModels, WebhooksIds, YesNo).source/Interfaces/ - Barrel re-exports of all TypeScript interfaces organized by domain (Common, Domains, Messages, Events, Suppressions, etc.).source/Types/ - Type aliases such as InputFormData and MailgunClientOptions consumed by the public API.source/Classes/MailgunClient.ts - Instantiates and wires together all sub-clients; returned by mailgun.client().source/Classes/Messages.ts - Implements messages.create() for sending email.source/Classes/Events.ts - Implements events.get() for event log queries.source/Classes/Webhooks.ts - CRUD for Mailgun webhook registrations.source/Classes/Routes.ts - Manages inbound routing rules.source/Classes/IPs.ts - Dedicated IP management.source/Classes/IPPools.ts - IP pool grouping and assignment.source/Classes/Subaccounts.ts - Subaccount creation and management.source/Classes/Domains/ - Full domain lifecycle: creation, credentials, SMTP keys, tracking settings, templates, and tags.source/Classes/Suppressions/ - Per-model suppression handlers for bounces, complaints, unsubscribes, and whitelists.source/Classes/MailingLists/ - Mailing list and member CRUD.source/Classes/Stats/ - Statistics retrieval (StatsClient) and result container (StatsContainer).source/Classes/Tags/ - Tag listing, updating, and deletion.source/Classes/Validations/ - Single address validation (validate) and bulk validation (multipleValidation).source/Classes/InboxPlacements/ - Inbox placement tests, seed list management, provider filters, results, and sharing.source/Classes/Metrics/ - Account/domain metrics queries.source/Classes/Logs/ - Log record retrieval.source/Classes/DKIM/ - DKIM key rotation and management.source/Classes/BounceClassification/ - Bounce classification code lookup.source/Classes/common/Request.ts - Core HTTP request wrapper using Axios.source/Classes/common/FormDataBuilder.ts - Builds multipart FormData for attachments and API payloads.source/Classes/common/NavigationThruPages.ts - Pagination helper used by list endpoints.source/Classes/common/AttachmentsHandler.ts - Normalizes attachment inputs before upload.source/Classes/common/Error.ts - Custom SDK error class with status code and body.source/Classes/common/RequestProviders/AxiosProvider.ts - Axios adapter wiring timeouts, proxies, and auth.url: 'https://api.eu.mailgun.net' to mailgun.client() when your sending domain is registered in the EU region.FormData is not defined in Node.js < 18: Either upgrade to Node 18+ (which provides global FormData) or install form-data and pass it: new Mailgun(require('form-data'))..js extension import errors in CommonJS projects: The source uses explicit .js extensions for ESM compatibility. In a CJS project, run the source through a bundler (esbuild, webpack) or switch your project to "type": "module".moduleResolution is node16 or bundler; node (classic) does not resolve .js-extensioned ESM imports correctly.axios directly. If your project pins a different major version, dedupe with npm dedupe or align versions to avoid duplicate Axios bundles.Buffer or Readable stream objects as attachment data, not plain file paths; the AttachmentsHandler does not resolve filesystem paths automatically.I have the Mailgun.js SDK source (mailgun.js v13) copied into `src/mailgun/`
in my Node.js TypeScript project. The integration guide is in `USAGE.md`.
The upstream package is `mailgun.js` on npm.
Please help me integrate this SDK step by step:
1. Read `USAGE.md` and `src/mailgun/index.ts` to understand the public API.
2. Install the required runtime dependencies: axios, base-64, url-join.
3. Create a `src/services/email.ts` module that:
- Instantiates `Mailgun` from `src/mailgun/index.ts` using the global FormData.
- Reads MAILGUN_API_KEY, MAILGUN_DOMAIN, and optionally MAILGUN_API_URL from env.
- Exports a `sendEmail(to, subject, html)` async function.
- Exports a `listBounces()` async function using `SuppressionModels.BOUNCES`.
4. Wire the service into my existing Express route at `src/routes/email.ts`.
5. Show tsconfig changes needed for the .js extension imports.
6. Do not invent any methods not present in `src/mailgun/` or documented in `USAGE.md`.
The upstream project is licensed under the MIT License (see source/LICENSE if present, or the mailgun.js repository). This block is derived from user@example.com published by Mailgun Technologies, Inc.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
Hướng dẫn cài đặt đầy đủ và prompt tích hợp sẽ mở khóa sau khi mua.
Automation, Utilities & Developer Tools
Miễn phí