@tozielinski/next-brevo-api-helper
v1.0.6
Published
Lightweight helper to use Brevo to send mails via the Brevo API and maintain all
Readme
next-brevo-api-helper
Using the Brevo API for create, update and delete contacts, folders and lists and send mails via the API
Quick Start
Install the package:
npm install @tozielinski/next-brevo-api-helperCreate an API Key in Brevo: and add it to your Next.js environment variables:
BREVO_API_KEY=your-brevo-api-keyhttps://www.brevo.com/api-keys
Create a ServerAction, and use it in your Next.js page:
'use server'
import {BrevoClient, BrevoEmailRecipient, BrevoSendEmailRequest} from "@tozielinski/next-brevo-api-helper";
const brevoClient = new BrevoClient();
const mail: BrevoSendEmailRequest = {
to:
[{
email: string
}]
,
// sender: {
// email: string
// } satisfies BrevoEmailRecipient,
// cc?: BrevoEmailRecipient[];
// bcc?: BrevoEmailRecipient[];
// replyTo?: {
// email: string,
// name?: string,
// } satisfies BrevoEmailRecipient,
// subject: string,
// htmlContent: string,
// textContent: string,
// textContent: string,
// templateId?: number;
// params?: Record<string, string | number | boolean>;
// headers?: Record<string, string>;
// attachment?: {
// url?: string;
// content?: string; // Base64 encoded
// name?: string;
// }[];
// tags?: string[];
};
export async function sendMail() {
return brevoClient.sendEmail(mail);
}
export async function getFolders(apiKey?:string) {
const brevoClient = new BrevoClient();
return brevoClient.getFolders();
}
export async function getFolderDetails(folderId: number, apiKey?:string) {
const brevoClient = new BrevoClient();
return brevoClient.getFolderDetails({id: folderId});
}
export async function createFolder(name: string) {
return brevoClient.createFolder({name: name});
}
export async function deleteFolder(id: number) {
return brevoClient.deleteFolder({id: id});
}