nuxt-mailchannels
Version:
MailChannels Email API integration for Nuxt
61 lines (60 loc) • 2.57 kB
TypeScript
import { type EmailsSendOptions } from 'mailchannels-sdk';
import { type H3Event } from 'h3';
interface EmailsSendOptionsWithOverrides extends Omit<EmailsSendOptions, 'to' | 'from'> {
to?: EmailsSendOptions['to'];
from?: EmailsSendOptions['from'];
}
export declare const useMailChannels: (event?: H3Event) => {
/**
* Send an email using MailChannels Email API
* @param options - The email options to send
* @param dryRun - When set to `true`, the message will not be sent. Instead, the fully rendered message will be returned in the `data` property of the response. The default value is `false`.
* @example
* ```ts
* // Inside an API route handler
* export default defineEventHandler(async (event) => {
* const mailchannels = useMailChannels(event)
*
* const { data, error } = await mailchannels.send({
* to: 'to@example.com',
* from: 'from@example.com',
* subject: 'Test',
* html: 'Test',
* })
*
* return { data }
* })
* ```
*/
send: (options: EmailsSendOptionsWithOverrides, dryRun?: boolean) => Promise<import("mailchannels-sdk").EmailsSendResponse>;
/**
* Queues an email message for asynchronous processing and returns immediately with a request ID.
*
* The email will be processed in the background, and you'll receive webhook events for all delivery status updates (e.g. `dropped`, `processed`, `delivered`, `hard-bounced`). These webhook events are identical to those sent for the synchronous /send endpoint.
*
* Use this endpoint when you need to send emails without waiting for processing to complete. This can improve your application's response time, especially when sending to multiple recipients.
* @param options - The email options to send.
* @example
* ```ts
* // Inside an API route handler
* export default defineEventHandler(async (event) => {
* const mailchannels = useMailChannels(event)
*
* const { data, error } = await mailchannels.queue({
* to: 'to@example.com',
* from: 'from@example.com',
* subject: 'Test',
* html: 'Test',
* })
*
* return { data }
* })
* ```
*/
queue: (options: EmailsSendOptionsWithOverrides) => Promise<import("mailchannels-sdk").EmailsQueueResponse>;
/**
* @deprecated Use `queue` instead.
*/
sendAsync: (options: EmailsSendOptionsWithOverrides) => Promise<import("mailchannels-sdk").EmailsQueueResponse>;
};
export {};