Skip to content

How I Built a Free Self-Hosted Email Setup with Cloudflare, Brevo and OpenInbox

Email Cloudflare Node.js Self-Hosting Open Source
How I Built a Free Self-Hosted Email Setup with Cloudflare, Brevo and OpenInbox

How I Built a Free Self-Hosted Email Setup with Cloudflare, Brevo and OpenInbox

My Node.js and EJS app needed to send email, and I wanted people to be able to reply to those emails and have the replies land in a real inbox that I control. Paid business email charges per user every month, so I looked for a setup that costs nothing and still works properly with my own domain.

This article walks through the full process and every tool I used. By the end you will know how to send email from a Node.js app using SMTP, receive replies on your own domain, and fix the most common errors along the way.

The Problem

I had two separate needs:

  1. Sending: my app has forms (such as submitting a tool or becoming a partner) that need to email an admin, and I also wanted to send some promotional email.
  2. Receiving: when someone replies to one of those emails, I want to read the reply in a proper mailbox, not lose it to a no-reply address.

Most services solve only one half of this, and the all-in-one options charge per seat.

The Goal

  • Use my own domain for both sending and receiving.
  • Keep the monthly cost at zero by staying inside free tiers.
  • Make sure emails are authenticated (SPF, DKIM, DMARC) so they do not land in spam.
  • Keep the Node.js code simple.

The Tools

Tool What I use it for
Domain registrar Buying the domain. Any registrar works.
Cloudflare DNS, Email Routing for incoming mail, and hosting the mailbox app on Workers.
OpenInbox An open-source webmail client that runs in my own Cloudflare account.
Brevo SMTP provider that delivers the outgoing mail from my app.
Other SMTP providers Optional alternatives or fallbacks, such as Resend, Mailjet, or Gmail SMTP with an app password.
Nodemailer The Node.js library that sends mail from my app.

Why this combination

  • Cloudflare receives mail for the domain through Email Routing and hands it to a Worker, so there is no mail server to maintain.
  • OpenInbox gives that incoming mail a real interface: inboxes, threads, search, aliases and shared mailboxes. It runs as one Worker and one D1 database in my own account.
  • Brevo handles outgoing delivery. Cloudflare Email Routing is for receiving, so I still need a sending provider.

OpenInbox supports Resend, Brevo, Mailjet and generic SMTP for sending, with fallback between providers. Their documented free daily limits are roughly 100 (Resend), 300 (Brevo) and 200 (Mailjet) emails per day. Check each provider's current limits before depending on them.

The Solution

The flow looks like this:

text
Node.js app → Brevo SMTP → recipient
                              │  (clicks Reply)
                              ▼
                    hello@yourdomain.com
                              ▼
          Cloudflare Email Routing → OpenInbox Worker

Outgoing mail goes through Brevo. Replies go to an address on my own domain, which Cloudflare routes into OpenInbox. Brevo is not involved in receiving.

Technical Implementation

Step 1: Buy a domain and move DNS to Cloudflare

  1. Buy a domain from any registrar.
  2. Create a free Cloudflare account and add the domain.
  3. Replace the registrar's nameservers with the two Cloudflare nameservers.
  4. Wait for Cloudflare to mark the domain as active.

OpenInbox requires the domain to be on Cloudflare's nameservers, because it manages Email Routing and DNS records for you.

Step 2: Deploy OpenInbox

OpenInbox deploys with a Deploy to Cloudflare button in its README.

  1. Click the deploy button and keep the default names.
  2. Open the Worker's workers.dev address.
  3. Create the Cloudflare API token from the setup page. The link pre-fills the permissions, so you only review and create it.
  4. Paste the token back and follow the setup page to create the admin account and connect your domain.
  5. Save the recovery key somewhere safe. It is shown once and is the only way back into the owner account if you lose your password.

OpenInbox describes itself as beta software. I recommend testing it on a spare domain before relying on it for important mail.

Step 3: Create the mailbox that receives replies

I created a real mailbox, hello@yourdomain.com, in OpenInbox. This matters because I do not use a no-reply address. If the sender is no-reply@, replies have nowhere useful to go.

Step 4: Set up Brevo

  1. Create a Brevo account.
  2. Add and authenticate your domain in Brevo's sender and domain settings.
  3. Add the DKIM record Brevo gives you to Cloudflare DNS.
  4. Make sure your domain has only one SPF record. Merge Brevo's include into the existing record instead of adding a second one.
  5. Keep a DMARC record in place.
  6. Verify hello@yourdomain.com as a sender.
  7. Generate an SMTP key in Brevo's SMTP settings.

Note that the SMTP login is the one Brevo shows you, which is usually not your account email.

Step 5: Configure the Node.js app

My app already had a form-notification block in its environment file. I pointed it at Brevo and added one extra variable for replies:

env
ADMIN_EMAIL=hello@yourdomain.com
MAIL_FROM=YourApp <hello@yourdomain.com>
SMTP_HOST=smtp-relay.brevo.com
SMTP_PORT=587
SMTP_SECURE=
SMTP_USER=your-brevo-smtp-login
SMTP_PASS=your-brevo-smtp-key
REPLY_TO=hello@yourdomain.com
RATE_FORM_PER_HOUR=5
FORM_MIN_SECONDS=3

Port 587 uses STARTTLS, so SMTP_SECURE stays empty. Use true only with port 465.

Step 6: Send mail with Nodemailer

js
const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  host: process.env.SMTP_HOST,
  port: Number(process.env.SMTP_PORT) || 587,
  secure: process.env.SMTP_SECURE === 'true',
  auth: {
    user: process.env.SMTP_USER,
    pass: process.env.SMTP_PASS,
  },
});

async function sendEmail(to, subject, html) {
  return transporter.sendMail({
    from: process.env.MAIL_FROM,
    replyTo: process.env.REPLY_TO || process.env.MAIL_FROM,
    to,
    subject,
    html,
  });
}

The important line is replyTo. It tells mail clients where replies should go, which is the address that Cloudflare routes into OpenInbox.

For promotional messages, I also add unsubscribe headers:

js
headers: {
  'List-Unsubscribe': '<mailto:unsubscribe@yourdomain.com>',
  'List-Unsubscribe-Post': 'List-Unsubscribe=One-Click',
}

These headers only help if you actually handle unsubscribes, so build an unsubscribe route in your app.

Challenges

Error: 525 5.7.1 Unauthorized IP address

The first time I sent a form email, my app logged this:

text
could not email admin: Invalid login: 525 5.7.1 Unauthorized IP address

The credentials were correct. Brevo has an IP authorization feature, and it was rejecting the IP my app connected from. The fix:

  1. In Brevo, open Security → Authorised IPs.
  2. Either add your server's IP, or deactivate blocking.

If your host uses changing outbound IPs, whitelisting will keep breaking, so deactivating blocking is more practical. In that case, keep the SMTP key secret and rotate it if it ever leaks. To find your server's current IP, run curl ifconfig.me on it.

Other errors to watch for

  • 535 Authentication failed: the SMTP login or key is wrong.
  • Sender not valid: the From address has not been verified in Brevo.
  • Emails going to spam: usually a DNS problem, such as a missing DKIM record or two SPF records.

What I Learned

  • Sending and receiving are separate problems. Cloudflare and OpenInbox solve receiving, and Brevo solves sending.
  • Never use no-reply if you want replies. Use a real mailbox as the From address.
  • DNS authentication is the foundation of deliverability. SPF, DKIM and DMARC must be correct before anything else matters.
  • Free tiers have real limits. Daily send limits, 500 MB of D1 storage and 100,000 Worker requests per day are the main ones to watch.

Responsible Sending

OpenInbox is for real conversations. It is not meant for cold outreach or bulk marketing, and its README says so clearly. My setup respects that, because the app sends through Brevo and OpenInbox only receives replies.

A few rules I follow for promotional email:

  • Only email people who agreed to hear from you.
  • Include a working unsubscribe link and your contact details.
  • Send in small batches, and increase volume gradually on a new domain.
  • For real campaigns, use a tool built for them, such as Brevo's campaign features, instead of pushing everything through plain SMTP.

Spam complaints and high bounce rates can get your provider account suspended and damage your domain's reputation.

Results

My app now sends form notifications and other email from my own domain, and replies arrive in my own OpenInbox mailbox. The running cost is the price of the domain, as long as I stay within free tiers.

Documentation

For setup details and current limits, read the official documentation:

Resources

Conclusion

With a domain, a free Cloudflare account, OpenInbox and a free SMTP provider like Brevo, you can send email from a Node.js app and read the replies in your own mailbox, with no per-user fees. The key points are to authenticate your domain, use a real reply address, and respect the limits and rules of every free tier you rely on.



Share this article

Back to top