vintasend-mailgun
v0.13.3
Published
A VintaSend email notification adapter using [Mailgun](https://www.mailgun.com/) for reliable email delivery with attachment support.
Readme
VintaSend Mailgun Adapter
A VintaSend email notification adapter using Mailgun for reliable email delivery with attachment support.
Installation
npm install vintasend-mailgun mailgun.js form-dataConfiguration
import { MailgunNotificationAdapterFactory } from 'vintasend-mailgun';
const adapter = new MailgunNotificationAdapterFactory().create(
templateRenderer,
false, // enqueueNotifications
{
apiKey: process.env.MAILGUN_API_KEY,
domain: process.env.MAILGUN_DOMAIN,
fromEmail: '[email protected]',
fromName: 'My App', // optional
}
);Configuration Options
interface MailgunConfig {
apiKey: string; // Mailgun API key
domain: string; // Mailgun domain
fromEmail: string; // Default sender email address
fromName?: string; // Optional sender name
}Usage
Basic Email
await notificationService.createNotification({
userId: '123',
notificationType: 'EMAIL',
contextName: 'welcome',
contextParameters: { firstName: 'John' },
title: 'Welcome!',
bodyTemplate: '/templates/welcome.pug',
subjectTemplate: '/templates/subjects/welcome.pug',
sendAfter: new Date(),
});Email with Attachments
import { readFile } from 'fs/promises';
await notificationService.createNotification({
userId: '123',
notificationType: 'EMAIL',
contextName: 'invoice',
contextParameters: { invoiceNumber: 'INV-001' },
title: 'Your invoice',
bodyTemplate: '/templates/invoice.pug',
subjectTemplate: '/templates/subjects/invoice.pug',
sendAfter: new Date(),
attachments: [
{
file: await readFile('./invoice.pdf'),
filename: 'invoice.pdf',
contentType: 'application/pdf',
},
],
});One-Off Notifications
await notificationService.createOneOffNotification({
emailOrPhone: '[email protected]',
firstName: 'Jane',
lastName: 'Smith',
notificationType: 'EMAIL',
contextName: 'order-confirmation',
contextParameters: { orderNumber: '12345' },
title: 'Order Confirmation',
bodyTemplate: '/templates/order-confirmation.pug',
subjectTemplate: '/templates/subjects/order-confirmation.pug',
sendAfter: new Date(),
});Features
- ✅ Email delivery via Mailgun API
- ✅ File attachments
- ✅ One-off notifications
- ✅ Scheduled notifications
- ✅ Custom sender name and email
- ✅ HTML email templates
- ✅ Multiple attachments per email
API Reference
MailgunNotificationAdapterFactory
class MailgunNotificationAdapterFactory<Config extends BaseNotificationTypeConfig>Methods:
create<TemplateRenderer>(templateRenderer, enqueueNotifications, config)- Create adapter instance
MailgunNotificationAdapter
Properties:
key: string- Returns'mailgun'notificationType: NotificationType- Returns'EMAIL'supportsAttachments: boolean- Returnstrue
Methods:
send(notification, context)- Send an email with optional attachments
Environment Variables
MAILGUN_API_KEY=key-your-api-key-here
MAILGUN_DOMAIN=mg.example.com
[email protected]
FROM_NAME=My ApplicationLicense
MIT
