Mastering Email Delivery on Cloud Platforms: Overcoming SMTP Blocks with Brevo's HTTP API

By • min read

Introduction

Email communication has become an indispensable part of modern web applications. Whether it's sending verification links, password reset instructions, or marketing updates, reliable email delivery is critical for user engagement and security. However, developers often encounter a frustrating roadblock: their email functionality works perfectly on local development environments but fails abruptly after deployment to cloud platforms like Render, Heroku, DigitalOcean, or AWS.

Mastering Email Delivery on Cloud Platforms: Overcoming SMTP Blocks with Brevo's HTTP API
Source: www.freecodecamp.org

This article delves into the underlying causes of these email delivery failures, explains why cloud providers block traditional SMTP traffic, and presents a robust, elegant solution using Brevo's HTTP API to ensure your emails are sent without interruption. By the end, you'll have a clear understanding and a practical implementation to bypass these restrictions.

Prerequisites

To follow along effectively, you should be comfortable with the following concepts:

The Problem: SMTP Blocking on Cloud Platforms

Many developers traditionally use Nodemailer, a popular Node.js library for sending emails via the Simple Mail Transfer Protocol (SMTP). For instance, you might configure it to use Gmail's SMTP server on port 587 (STARTTLS) or port 465 (SSL). Locally, this works flawlessly. But once deployed, your application suddenly stops sending emails without clear error messages.

Why does this happen? Cloud providers are constantly fighting spam abuse. Malicious actors spin up free-tier instances to blast millions of unsolicited emails, which leads to entire IP ranges being blacklisted. To protect their infrastructure and maintain deliverability, providers like Render, Heroku, and DigitalOcean often block outgoing SMTP connections, especially on ports 25, 465, and 587. This is a common pain point, as documented in many developer forums.

Even if you switch to a dedicated email service like SendGrid or Mailgun, you may still encounter blocks if you use their SMTP endpoints. The solution lies in moving away from SMTP entirely and using HTTP APIs, which are allowed on most cloud platforms.

The Modern Trap: Domain Verification

Some developers attempt to work around the block by using services that require domain verification (e.g., setting up SPF, DKIM, and MX records). While these are essential for long-term deliverability, they don't solve the immediate problem of blocked SMTP ports. Moreover, domain verification can be time-consuming and requires access to DNS settings, which may not be feasible for rapid prototypes or internal tools.

The real issue is not about proving you own a domain; it's about how you send the email. SMTP uses a persistent connection that cloud providers cannot easily monitor, whereas HTTP requests are stateless and can be inspected for abuse. Therefore, the most reliable approach is to use an HTTP-based email API.

The Ultimate Solution: Brevo and HTTP APIs

Brevo (formerly Sendinblue) offers a powerful, HTTP-based email API that works on any cloud platform. Because it uses standard HTTPS requests (port 443), it bypasses SMTP restrictions entirely. Additionally, Brevo provides generous free tiers, making it ideal for development and small projects.

In this section, we'll walk through setting up a Node.js/Express application that sends emails via Brevo's API. We'll cover backend configuration, API key management, and a reusable email function.

Backend Setup

Start by creating a new Node.js project and installing the required dependencies:

npm init -y
npm install express dotenv

Create an .env file to store sensitive credentials:

BREVO_API_KEY=your_brevo_api_key_here

Load the environment variables in your main server file (server.js).

Mastering Email Delivery on Cloud Platforms: Overcoming SMTP Blocks with Brevo's HTTP API
Source: www.freecodecamp.org

Brevo Configuration

First, sign up for a free Brevo account at brevo.com. After logging in, navigate to the API Keys section under your account settings and generate a new key. Copy it to your .env file.

Next, you'll need to create an HTTP request function that interacts with the Brevo API endpoint: https://api.brevo.com/v3/smtp/email. This endpoint accepts a JSON payload containing the sender, recipient, subject, and body (HTML or plain text).

Creating the Email Function

Define a reusable asynchronous function that sends an email using the native fetch() API (available in Node.js 18+). If you're using an older version, you can install node-fetch.

const sendEmail = async ({ to, subject, htmlBody }) => {
  const url = 'https://api.brevo.com/v3/smtp/email';
  const payload = {
    sender: { email: 'your_verified_sender@example.com', name: 'Your App' },
    to: [{ email: to }],
    subject,
    htmlContent: htmlBody
  };

  const response = await fetch(url, {
    method: 'POST',
    headers: {
      'api-key': process.env.BREVO_API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(payload)
  });

  if (!response.ok) {
    throw new Error(`Brevo API error: ${response.statusText}`);
  }

  return response.json();
};

Make sure the sender email address is verified in your Brevo account. You can verify one free email address.

Integrating the Function into an Express Route

Now, create an Express route that receives email details from a client and calls the sendEmail function.

const express = require('express');
const app = express();
app.use(express.json());

app.post('/send-email', async (req, res) => {
  const { to, subject, htmlBody } = req.body;
  try {
    const result = await sendEmail({ to, subject, htmlBody });
    res.status(200).json({ success: true, messageId: result.messageId });
  } catch (error) {
    console.error('Email sending failed:', error);
    res.status(500).json({ success: false, error: error.message });
  }
});

app.listen(3000, () => console.log('Server running on port 3000'));

Test the endpoint locally using a tool like Postman or curl. Once it works, deploy your application to a cloud platform. The email function will continue to function because it uses HTTPS—not SMTP.

Conclusion

Cloud platforms are essential for modern web development, but their security measures can interfere with traditional email delivery methods. By switching from SMTP to an HTTP-based API like Brevo, you bypass these restrictions entirely. This approach is not only more reliable but also simpler to implement and maintain. You no longer have to worry about port blocking or domain verification delays.

We've covered the root cause of SMTP blocking, introduced Brevo as a solution, and walked through a concrete implementation in Node.js and Express. Now you can confidently deploy email functionality to any cloud provider without unexpected failures.

For further reading, explore Brevo's official documentation to customize email templates, handle attachments, or track delivery status. Happy coding!

Recommended

Discover More

Navigating Restartable Sequences: A Technical Guide to API Compliance and Hyrum's Law in Kernel DevelopmentUnderstanding the Linux 'Copy Fail' Vulnerability: Privilege Escalation ExplainedReact Native 0.80: Refining the JavaScript API for Stability and Type Safety10 Critical Insights Into the State of Preschool Funding and Quality in AmericaByteDance's Astra: 7 Crucial Facts About the Dual-Model Robot Navigation System