{"_id":"@apiclient.xyz/mailgun","name":"@apiclient.xyz/mailgun","dist-tags":{"latest":"2.0.3"},"versions":{"2.0.3":{"name":"@apiclient.xyz/mailgun","version":"2.0.3","private":false,"description":"an api abstraction package for mailgun","main":"dist_ts/index.js","typings":"dist_ts/index.d.ts","type":"module","author":{"name":"Lossless GmbH"},"license":"MIT","devDependencies":{"@git.zone/tsbuild":"^2.1.65","@git.zone/tstest":"^2.6.2","@push.rocks/qenv":"^6.1.3","@push.rocks/tapbundle":"^6.0.3","@types/node":"^22.0.0"},"dependencies":{"@push.rocks/smartfile":"^11.2.7","@push.rocks/smartmail":"^2.1.0","@push.rocks/smartrequest":"^4.3.2","@push.rocks/smartsmtp":"^3.0.3","@push.rocks/smartstring":"^4.0.2"},"browserslist":["last 1 chrome versions"],"repository":{"type":"git","url":"git+https://gitlab.com/mojoio/mailgun.git"},"bugs":{"url":"https://gitlab.com/mojoio/mailgun/issues"},"homepage":"https://gitlab.com/mojoio/mailgun#readme","scripts":{"test":"(tstest test/ --verbose)","build":"(tsbuild --web --allowimplicitany)","format":"(gitzone format)","buildDocs":"tsdoc"},"_id":"@apiclient.xyz/mailgun@2.0.3","_integrity":"sha512-c0S7ykY5Xjd8EeFYE889hYHLYgGJikmo14BbNZtd9t0WC++y6HYvdMzX4uhLcQlO5YMNx6P6tRPZkBrMK0Wjhw==","_resolved":"/tmp/e8b046f213a36047cd16ad2aa6a6a599/apiclient.xyz-mailgun-2.0.3.tgz","_from":"file:apiclient.xyz-mailgun-2.0.3.tgz","_nodeVersion":"23.8.0","_npmVersion":"11.3.0","dist":{"integrity":"sha512-c0S7ykY5Xjd8EeFYE889hYHLYgGJikmo14BbNZtd9t0WC++y6HYvdMzX4uhLcQlO5YMNx6P6tRPZkBrMK0Wjhw==","shasum":"b64b4c0fdba0d8ec280a0dcd68743185e195931e","tarball":"https://registry.npmjs.org/@apiclient.xyz/mailgun/-/mailgun-2.0.3.tgz","fileCount":26,"unpackedSize":42224,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICqaAs0oboymq3pH9ADCMSWhPMlEiNFTu+VeeiMUdNw9AiApzAmKJACwT1C8D2e0Het/tj0vvE0WZG1glvhyMDfEsQ=="}]},"_npmUser":{"name":"lossless","email":"hello@lossless.com"},"directories":{},"maintainers":[{"name":"lossless","email":"hello@lossless.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mailgun_2.0.3_1760696649283_0.001242491639553256"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-17T10:24:09.151Z","2.0.3":"2025-10-17T10:24:09.471Z","modified":"2025-10-17T10:24:09.818Z"},"maintainers":[{"name":"lossless","email":"hello@lossless.com"}],"description":"an api abstraction package for mailgun","homepage":"https://gitlab.com/mojoio/mailgun#readme","repository":{"type":"git","url":"git+https://gitlab.com/mojoio/mailgun.git"},"author":{"name":"Lossless GmbH"},"bugs":{"url":"https://gitlab.com/mojoio/mailgun/issues"},"license":"MIT","readme":"# @apiclient.xyz/mailgun\n\n> 🚀 A modern, TypeScript-first API wrapper for Mailgun with smart fallback mechanisms\n\nSend transactional emails through Mailgun's powerful API with an elegant, type-safe interface. This package seamlessly integrates with the [@push.rocks/smartmail](https://www.npmjs.com/package/@push.rocks/smartmail) ecosystem and provides automatic SMTP fallback for edge cases.\n\n## Why @apiclient.xyz/mailgun? 💡\n\n- **🎯 TypeScript Native** - Full type safety with excellent IntelliSense support\n- **🔄 Smart Fallback** - Automatically falls back to SMTP when API limitations are hit\n- **📎 Attachment Support** - Hassle-free file attachments with built-in handling\n- **🌍 Multi-Region** - Support for both EU and US Mailgun regions\n- **📬 Message Retrieval** - Fetch stored messages from Mailgun's API\n- **🔗 Webhook Integration** - Easy integration with Mailgun webhooks\n- **⚡ Modern API** - Clean, fluent interface powered by smartrequest v4\n\n## Installation\n\n```bash\nnpm install @apiclient.xyz/mailgun\n# or\npnpm install @apiclient.xyz/mailgun\n# or\nyarn add @apiclient.xyz/mailgun\n```\n\n## Quick Start 🚀\n\n```typescript\nimport { MailgunAccount } from '@apiclient.xyz/mailgun';\nimport { Smartmail } from '@push.rocks/smartmail';\n\n// Initialize your Mailgun account\nconst mailgun = new MailgunAccount({\n  apiToken: 'your-mailgun-api-token',\n  region: 'eu' // or 'us'\n});\n\n// Create and send an email\nconst email = new Smartmail({\n  from: 'Your App <noreply@yourdomain.com>',\n  subject: 'Welcome to Our Service! 🎉',\n  body: '<h1>Hello!</h1><p>Thanks for signing up.</p>'\n});\n\nawait mailgun.sendSmartMail(email, 'user@example.com');\n```\n\n## Core Features\n\n### 📧 Sending Emails\n\nThe primary way to send emails is through the `sendSmartMail()` method, which accepts a `Smartmail` object:\n\n```typescript\nimport { MailgunAccount } from '@apiclient.xyz/mailgun';\nimport { Smartmail } from '@push.rocks/smartmail';\n\nconst mailgun = new MailgunAccount({\n  apiToken: process.env.MAILGUN_API_TOKEN,\n  region: 'eu'\n});\n\n// Create a rich HTML email\nconst email = new Smartmail({\n  from: 'Team <hello@yourdomain.com>',\n  subject: 'Monthly Newsletter',\n  body: `\n    <html>\n      <body>\n        <h1>What's New This Month</h1>\n        <p>Check out our latest updates...</p>\n      </body>\n    </html>\n  `\n});\n\n// Send to a recipient\nawait mailgun.sendSmartMail(email, 'subscriber@example.com');\n```\n\n### 📎 Email Attachments\n\nAdd attachments seamlessly using the smartmail interface:\n\n```typescript\nimport { SmartFile } from '@push.rocks/smartfile';\n\nconst email = new Smartmail({\n  from: 'Sales <sales@yourdomain.com>',\n  subject: 'Your Invoice',\n  body: '<p>Please find your invoice attached.</p>'\n});\n\n// Add attachment from file\nconst pdfFile = await SmartFile.fromFilePath('./invoice.pdf');\nemail.addAttachment(pdfFile);\n\nawait mailgun.sendSmartMail(email, 'customer@example.com');\n```\n\n### 🔄 SMTP Fallback\n\nFor edge cases where the Mailgun API has limitations (like empty email bodies), the package automatically falls back to SMTP:\n\n```typescript\n// Configure SMTP credentials for fallback\n// Format: domain|username|password\nawait mailgun.addSmtpCredentials(\n  'yourdomain.com|postmaster@yourdomain.com|your-smtp-password'\n);\n\n// This email with empty body will automatically use SMTP\nconst emptyBodyEmail = new Smartmail({\n  from: 'System <system@yourdomain.com>',\n  subject: 'System Notification',\n  body: ''\n});\n\nawait mailgun.sendSmartMail(emptyBodyEmail, 'admin@example.com');\n// ✅ Automatically sent via SMTP instead of API\n```\n\n### 📬 Retrieving Messages\n\nFetch stored messages from Mailgun's API:\n\n```typescript\n// Retrieve by message URL (from Mailgun storage)\nconst message = await mailgun.retrieveSmartMailFromMessageUrl(\n  'https://sw.api.mailgun.net/v3/domains/yourdomain.com/messages/...'\n);\n\nif (message) {\n  console.log('Subject:', message.options.subject);\n  console.log('From:', message.options.from);\n  console.log('Body:', message.options.body);\n\n  // Attachments are automatically fetched\n  console.log('Attachments:', message.attachments.length);\n}\n```\n\n### 🔔 Webhook Integration\n\nProcess Mailgun webhook notifications:\n\n```typescript\n// In your webhook handler\napp.post('/webhooks/mailgun', async (req, res) => {\n  const payload = req.body;\n\n  // Retrieve the full message from the webhook payload\n  const message = await mailgun.retrieveSmartMailFromNotifyPayload(payload);\n\n  if (message) {\n    // Process the received email\n    console.log('Received email:', message.options.subject);\n  }\n\n  res.status(200).send('OK');\n});\n```\n\n## API Reference\n\n### MailgunAccount\n\n#### Constructor\n\n```typescript\nnew MailgunAccount(options: {\n  apiToken: string;  // Your Mailgun API token\n  region: 'eu' | 'us';  // Mailgun region\n})\n```\n\n#### Methods\n\n##### `sendSmartMail(smartmail, recipient, data?)`\n\nSend an email through Mailgun.\n\n```typescript\nawait mailgun.sendSmartMail(\n  smartmailInstance,\n  'recipient@example.com',\n  { customData: 'optional' }  // Optional template data\n);\n```\n\n##### `addSmtpCredentials(credentials)`\n\nConfigure SMTP fallback credentials.\n\n```typescript\nawait mailgun.addSmtpCredentials('domain|username|password');\n```\n\n##### `retrieveSmartMailFromMessageUrl(url)`\n\nRetrieve a stored message by its Mailgun URL.\n\n```typescript\nconst message = await mailgun.retrieveSmartMailFromMessageUrl(messageUrl);\n```\n\n##### `retrieveSmartMailFromNotifyPayload(payload)`\n\nExtract and retrieve a message from a Mailgun webhook payload.\n\n```typescript\nconst message = await mailgun.retrieveSmartMailFromNotifyPayload(webhookPayload);\n```\n\n## Region Support 🌍\n\nMailgun operates in multiple regions. Choose the appropriate one for your needs:\n\n- **`eu`** - European region (GDPR compliant, data stored in EU)\n- **`us`** - US region (data stored in US)\n\n```typescript\n// EU region\nconst mailgunEU = new MailgunAccount({\n  apiToken: 'your-token',\n  region: 'eu'\n});\n\n// US region\nconst mailgunUS = new MailgunAccount({\n  apiToken: 'your-token',\n  region: 'us'\n});\n```\n\n## Advanced Usage\n\n### Template Variables with Smartmail\n\nUse template variables in your emails:\n\n```typescript\nimport { Smartmail } from '@push.rocks/smartmail';\n\nconst welcomeEmail = new Smartmail({\n  from: 'Welcome Team <welcome@yourdomain.com>',\n  subject: 'Welcome {{userName}}!',\n  body: '<h1>Hi {{userName}}</h1><p>Your account is ready!</p>'\n});\n\n// Pass template data\nawait mailgun.sendSmartMail(\n  welcomeEmail,\n  'newuser@example.com',\n  { userName: 'John Doe' }\n);\n```\n\n### Error Handling\n\n```typescript\ntry {\n  await mailgun.sendSmartMail(email, 'user@example.com');\n  console.log('✅ Email sent successfully');\n} catch (error) {\n  console.error('❌ Failed to send email:', error.message);\n}\n```\n\n### Batch Sending\n\nSend multiple emails efficiently:\n\n```typescript\nconst recipients = [\n  'user1@example.com',\n  'user2@example.com',\n  'user3@example.com'\n];\n\nconst email = new Smartmail({\n  from: 'Newsletter <news@yourdomain.com>',\n  subject: 'Weekly Update',\n  body: '<p>Here is your weekly update...</p>'\n});\n\n// Send to all recipients\nawait Promise.all(\n  recipients.map(recipient =>\n    mailgun.sendSmartMail(email, recipient)\n  )\n);\n```\n\n## TypeScript Support 📘\n\nThis package is written in TypeScript and provides full type definitions out of the box:\n\n```typescript\nimport {\n  MailgunAccount,\n  IMailgunAccountContructorOptions,\n  IMailgunMessage\n} from '@apiclient.xyz/mailgun';\n\n// Full IntelliSense support\nconst options: IMailgunAccountContructorOptions = {\n  apiToken: 'token',\n  region: 'eu'\n};\n\nconst mailgun = new MailgunAccount(options);\n```\n\n## Dependencies\n\nThis package leverages the powerful @push.rocks ecosystem:\n\n- **[@push.rocks/smartrequest](https://www.npmjs.com/package/@push.rocks/smartrequest)** - Modern HTTP client\n- **[@push.rocks/smartmail](https://www.npmjs.com/package/@push.rocks/smartmail)** - Email composition\n- **[@push.rocks/smartsmtp](https://www.npmjs.com/package/@push.rocks/smartsmtp)** - SMTP fallback\n- **[@push.rocks/smartfile](https://www.npmjs.com/package/@push.rocks/smartfile)** - File handling\n- **[@push.rocks/smartstring](https://www.npmjs.com/package/@push.rocks/smartstring)** - String utilities\n\n## Links & Resources\n\n- **📦 [NPM Package](https://www.npmjs.com/package/@apiclient.xyz/mailgun)**\n- **💻 [GitLab Repository](https://gitlab.com/apiclient.xyz/mailgun)**\n- **🪞 [GitHub Mirror](https://github.com/apiclient-xyz/mailgun)**\n- **📚 [TypeDoc Documentation](https://apiclient.xyz/mailgun/docs/)**\n- **🌐 [Mailgun API Docs](https://documentation.mailgun.com/)**\n\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.\n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH\nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n","readmeFilename":"readme.md","_rev":"1-ea5d88681b9ab5004c3cbca42f4c04ee"}