Invia email da Node.js
Installa @getbrevo/brevo, crea un BrevoClient con la tua chiave API e chiama sendTransacEmail, oppure punta Nodemailer al relay SMTP di Brevo.

Come funziona
npm install @getbrevo/brevo
import { BrevoClient } from '@getbrevo/brevo';
const brevo = new BrevoClient({ apiKey: 'your-api-key' });
const result = await brevo.transactionalEmails.sendTransacEmail({
subject: 'Hello from Brevo!',
htmlContent: '<html><body><p>Hello,</p><p>This is my first transactional email.</p></body></html>',
sender: { name: 'Alex from Brevo', email: '[email protected]' },
to: [{ email: '[email protected]', name: 'John Doe' }],
});
console.log('Email sent. Message ID:', result.messageId);
npm install nodemailer
const nodemailer = require("nodemailer");
let transporter = nodemailer.createTransport({
host: "smtp-relay.brevo.com",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: "[email protected]", // generated brevo user
pass: "xxxxxxxxx", // generated brevo password
},
});
curl --request POST \
--url https://api.brevo.com/v3/smtp/email \
--header 'accept: application/json' \
--header 'api-key:YOUR_API_KEY' \
--header 'content-type: application/json' \
--data '{
"sender":{
"name":"Alex from Brevo",
"email":"[email protected]"
},
"to":[
{
"email":"[email protected]",
"name":"John Doe"
}
],
"subject":"Hello from Brevo!",
"textContent":"Hello. This is my first transactional email sent from Brevo."
}'
Chiedi al tuo agente IA
Dai questo prompt a un agente IA collegato al server Brevo MCP.
Prima di inviare email dalla mia app Node.js, verifica che io abbia un mittente verificato e un dominio di invio autenticato. Elenca cosa manca.
Configura
Crea le tue chiavi e verifica un dominio
In Settings, apri SMTP & API > API keys & MCP. Dai a una chiave API accesso Restricted per ogni risorsa. Il relay SMTP richiede una chiave SMTP, non una chiave API. Configura prima il dominio di invio e il mittente.
Installa e invia
Esegui npm install @getbrevo/brevo, crea un BrevoClient con la tua apiKey e chiama brevo.transactionalEmails.sendTransacEmail con un oggetto, un mittente, un elenco to e un solo tipo di corpo: HTML, testo o un ID template. L'SDK richiede Node.js 18+.
Controlla il risultato
La quick start stampa result.messageId dopo l'invio. Verifica la consegna in Transactional, poi Email logs. Imposta timeoutInSeconds e maxRetries nel costruttore di BrevoClient. timeoutInSeconds ha 60 come valore predefinito e maxRetries ha 2.


