Resend transport implementation for sending emails via Resend API.
This transport provides efficient email delivery using Resend's HTTP API, with support for authentication, retry logic, batch sending capabilities, and idempotency for reliable delivery.
Example 1
Example 1
import { ResendTransport } from '@upyo/resend'; const transport = new ResendTransport({ apiKey: 'your-resend-api-key', 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(', ')); }
ResendTransport(config: ResendConfig)
Creates a new Resend transport instance.
The resolved Resend configuration used by this transport.
httpClient: ResendHttpClient
canUseBatchApi(messages: Message[]): boolean
Checks if messages can use Resend's batch API.
Batch API limitations:
- No attachments
- No tags
- No scheduled sending
chunkArray<T>(array: T[],size: number,): T[][]
Splits an array into chunks of specified size.
Sends a single email message via Resend API.
This method converts the message to Resend format, makes an HTTP request to the Resend API with automatic idempotency key generation, and returns a receipt with the result.
sendBatch(messages: Message[],options?: TransportOptions,): AsyncIterable<Receipt>
Sends a batch of messages using Resend's batch API.
sendMany(messages: Iterable<Message> | AsyncIterable<Message>,options?: TransportOptions,): AsyncIterable<Receipt>
Sends multiple email messages efficiently via Resend API.
This method intelligently chooses between single requests and batch API based on message count and features used. For optimal performance:
- Uses batch API for ≤100 messages without attachments or tags
- Falls back to individual requests for messages with unsupported features
- Chunks large batches (>100) into multiple batch requests
sendManyOptimized(messages: Message[],options?: TransportOptions,): AsyncIterable<Receipt>
Optimized batch sending that chooses the best strategy based on message features.