Plunk transport implementation for sending emails via Plunk API.
This transport provides efficient email delivery using Plunk's HTTP API, with support for both cloud-hosted and self-hosted instances, authentication, retry logic, and batch sending capabilities.
Example 1
Example 1
import { PlunkTransport } from '@upyo/plunk'; const transport = new PlunkTransport({ apiKey: 'your-plunk-api-key', baseUrl: 'https://api.useplunk.com', // or self-hosted URL timeout: 30000, retries: 3 }); const receipt = await transport.send(message); if (receipt.successful) { console.log('Message sent with ID:', receipt.messageId); } else { console.error('Send failed:', receipt.errorMessages.join(', ')); }
PlunkTransport(config: PlunkConfig)
Creates a new Plunk transport instance.
The resolved Plunk configuration used by this transport.
httpClient: PlunkHttpClient
extractMessageId(message: Message,): string
Extracts or generates a message ID from the Plunk response.
Plunk returns email details in the response, so we can use the contact ID and timestamp to create a meaningful message ID.
Sends a single email message via Plunk API.
This method converts the message to Plunk format, makes an HTTP request to the Plunk API, and returns a receipt with the result.
sendMany(messages: Iterable<Message> | AsyncIterable<Message>,options?: TransportOptions,): AsyncIterable<Receipt>
Sends multiple email messages efficiently via Plunk API.
This method sends each message individually but provides a streamlined interface for processing multiple messages. Each message is sent as a separate API request to Plunk.