For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Help CenterAPI KeysStatusSign In
GuidesAPI ReferenceChangelog
GuidesAPI ReferenceChangelog
  • Getting started
    • Overview
    • Quickstart
    • Authentication
    • Rate limits
  • Messaging API
    • Send transactional email
      • Batch send emails
      • Batch email idempotency
      • Schedule emails
      • Sandbox mode
      • Weekly event exports
      • SMTP relay integration
        • Postfix integration
        • Node.js example
      • Delete transactional logs
      • Parse inbound email
    • Send transactional SMS
    • Send transactional WhatsApp
  • Marketing Platform
    • Manage your contacts
    • Track website activity
    • Send WhatsApp campaigns
    • Weekly event exports
  • Webhooks
    • Getting started
    • Conversations webhooks
    • Payment webhooks
    • Marketing webhooks
    • Transactional webhooks
    • Loyalty webhooks
    • Batched webhooks
    • Secure webhook calls
    • Meetings and phone webhooks
    • Push notification webhooks
    • Sales CRM webhooks
  • Conversations
    • Getting started
    • Customize the chat widget
    • JavaScript API reference
    • REST API reference
    • Conversations webhooks
  • eCommerce
    • Activate eCommerce app
    • Manage product categories
    • Manage products
    • Manage orders
    • Coupon collections
    • eCommerce tracker events
  • Loyalty
    • Overview
    • Set up a program
    • Enroll members
    • Credit & debit points
    • Read member data
    • Best practices
  • Custom Objects
    • Custom objects management
  • Brevo tracker and events
    • Getting started
    • JavaScript implementation
    • REST implementation
    • Legacy tracker documentation
    • Events
  • Accounts and settings
    • Senders and domains
    • User activity logs
    • External feeds
    • Invited users
LogoLogo
Help CenterAPI KeysStatusSign In
On this page
  • Install nodemailer in your Node project
  • Include the library in your working class
  • Declare your SMTP credentials
  • Compose your email object
  • Trigger your email
Messaging APISend transactional emailSMTP relay integration

Node.js example

Was this page helpful?
Previous

Delete transactional logs

Next
Built with

Use this Node.js code and enter your own details to run the SMTP relay.

Install nodemailer in your Node project

Run this command in your working directory:

1npm install nodemailer

Include the library in your working class

1const nodemailer = require("nodemailer");

Declare your SMTP credentials

Specify your Brevo credentials to establish a connection between our server and your application. Use the createTransport object to define these values.

1 let transporter = nodemailer.createTransport({
2 host: "smtp-relay.brevo.com",
3 port: 587,
4 secure: false, // true for 465, false for other ports
5 auth: {
6 user: "example@brevo.com", // generated ethereal user
7 pass: "xxxxxxxxx", // generated ethereal password
8 },
9 });

Compose your email object

Specify the content and metadata of the email message to send through the transporter object. This example uses text content only, but you can also use a predefined templateId.

1 // send mail with defined transport object
2 let info = await transporter.sendMail({
3 from: '"Joe" example@brevo.com', // sender address
4 to: "hi@mail.com", // list of receivers
5 subject: "Hello ✔", // Subject line
6 text: "Hello {{ contact.FIRSTNAME }} , This is an SMTP message with customizations", // plain text body
7 });

Trigger your email

Specify the content and metadata of the email message to send through the transporter object. This example uses text content only, but you can also use a predefined templateId. The full example is below.

1const nodemailer = require("nodemailer");
2
3async function main() {
4
5
6 // create reusable transporter object using the default SMTP transport
7 let transporter = nodemailer.createTransport({
8 host: "smtp-relay.brevo.com",
9 port: 587,
10 secure: false, // true for 465, false for other ports
11 auth: {
12 user: "user@brevo.com", // generated brevo user
13 pass: "xxxxxxxxx", // generated brevo password
14 },
15 });
16
17 // send mail with defined transport object
18 let info = await transporter.sendMail({
19 from: '"mauricio@brevo.com', // sender address
20 to: "john@domain.com", // list of receivers
21 subject: "Hello ✔", // Subject line
22 text: "Hello {{ contact.FIRSTNAME }} , This is an SMTP message with customizations", // plain text body
23 });
24
25 console.log("Message sent: %s", info.messageId);
26 // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
27}
28
29main().catch(console.error);

Note: this example adds customizations to your SMTP email. It uses the contact’s attributes if the contact exists in Brevo. Run this JS code from the command line, or use the Send a Transactional Email API endpoint.