Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sendinblue / Brevo Tutorials

Sendinblue is now Brevo. This repo uses Brevo's current Node.js SDK, @getbrevo/brevo, with a small Express app.

The examples cover:

  • send a transactional email with inline HTML/text
  • send with a Brevo template
  • send batch transactional messages with messageVersions
  • create or update a contact
  • create a transactional webhook
  • receive webhook events locally

Demo Index

  • Express quickstart routes - the runnable root app with transactional sends, template sends, batch sends, contacts, webhook creation, and local webhook receiving.

What you need

  • Node.js 20+
  • A Brevo API key
  • A verified Brevo sender or sending domain

Setup

npm install
cp env.template .env
npm run dev

Fill in .env:

BREVO_API_KEY=xkeysib-xxxxxxxxx
BREVO_FROM_EMAIL=sender@example.com
BREVO_FROM_NAME=Tutorial App
BREVO_TO_EMAIL=recipient@example.com
BREVO_WEBHOOK_TOKEN=
PORT=3000

BREVO_WEBHOOK_TOKEN is optional. If you set it, configure the same value as a custom webhook header and the local receiver will reject requests without it.

Routes

Health check

curl http://127.0.0.1:3000/health

Send a transactional email

curl -X POST http://127.0.0.1:3000/send-email \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Hello from Brevo",
    "htmlContent": "<p>Your order {{params.orderNumber}} is confirmed.</p>",
    "params": { "orderNumber": "A-1043" },
    "tags": ["tutorial"]
  }'

Send with a template

curl -X POST http://127.0.0.1:3000/send-template \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": 8,
    "params": { "name": "Ada", "plan": "Pro" }
  }'

Send a batch

Brevo batch transactional sends use messageVersions. Put every recipient inside a version.

curl -X POST http://127.0.0.1:3000/send-batch \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Order confirmation",
    "htmlContent": "<p>Hello {{params.name}}, order {{params.orderNumber}} is ready.</p>",
    "messageVersions": [
      {
        "to": [{ "email": "one@example.com", "name": "One" }],
        "params": { "name": "One", "orderNumber": "A-100" }
      },
      {
        "to": [{ "email": "two@example.com", "name": "Two" }],
        "params": { "name": "Two", "orderNumber": "A-101" }
      }
    ]
  }'

Create or update a contact

curl -X POST http://127.0.0.1:3000/contacts \
  -H "Content-Type: application/json" \
  -d '{
    "email": "ada@example.com",
    "attributes": { "FIRSTNAME": "Ada" },
    "listIds": [2],
    "updateEnabled": true
  }'

Create a transactional webhook

The URL must be public HTTPS for production. During local development, use a tunnel.

curl -X POST http://127.0.0.1:3000/webhooks \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/webhooks/brevo",
    "events": ["delivered", "hardBounce", "spam"],
    "description": "Tutorial transactional events"
  }'

Receive webhooks

POST /webhooks/brevo

Incoming events are saved under webhooks/.

References

About

Node.js and Express tutorials for email deliverability with Brevo, formerly Sendinblue.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages