//native
type Brevo = {
apiKey: string;
};
/**
* Send a transactional email
*
*/
export async function main(
auth: Brevo,
body: {
sender?: { name?: string; email?: string; id?: number };
to?: { email: string; name?: string }[];
bcc?: { email: string; name?: string }[];
cc?: { email: string; name?: string }[];
htmlContent?: string;
textContent?: string;
subject?: string;
replyTo?: { email: string; name?: string };
attachment?: { url?: string; content?: string; name?: string }[];
headers?: {};
templateId?: number;
params?: {};
messageVersions?: {
to: { email: string; name?: string }[];
params?: {};
bcc?: { email: string; name?: string }[];
cc?: { email: string; name?: string }[];
replyTo?: { email: string; name?: string };
subject?: string;
htmlContent?: string;
textContent?: string;
}[];
tags?: string[];
scheduledAt?: string;
batchId?: string;
},
) {
const url = new URL(`https://api.brevo.com/v3/smtp/email`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago