Guides

A self-hosted email API: what it takes to run your own

What you need to run an email API on your own server: the machine, the DNS, the ports and a way to deliver. OpenSend does it as one program.

4 min read

In short

  • Running the API and the dashboard yourself is the easy half. Delivering the mail is the hard half.
  • OpenSend on a server of your own is one program and one folder: the dashboard, the API, the MCP server and a SQLite database.
  • Today such a server sends through Nextmail, with a key of your own account. The sending engine for your own server is written and not released.
  • The installer is written for Debian and Ubuntu. It is not published yet, and this post says plainly what is ready.

The two halves of an email service

An email API is two things, and they are not equally hard to host.

  • The application. It takes requests, keeps emails, contacts and keys, draws the dashboard and runs the schedule. It is a web service like any other.
  • The delivery. It signs each email, hands it to the mail server of the recipient and listens for what comes back. Whether that works depends on the reputation of the address it sends from, which takes time to earn.

Most projects that call themselves a self-hosted email API host the first half and rent the second. That is a fair design, and it is worth knowing which half you are getting.

What you run

One program serves the dashboard, the API, the docs and the MCP server from one address. It keeps everything in one folder: a SQLite database and the files of your emails. It also runs the schedule that sends broadcasts and moves automations along, once a minute.

It is the same code as our cloud, so every page of the docs holds on your server too.

What you need

  • A server with Debian or Ubuntu and root access.
  • A name that points at it with an A record, such as mail.example.com. People open the dashboard there, and programs call the API there.
  • Ports 80 and 443 open, for the certificate and for https.
  • One secret of at least 32 characters, made once. It signs every session and seals what the database stores.

To deliver from the server itself you also need port 25 open in both directions and a PTR record that names the server. Many hosting companies keep port 25 closed on a new account until you ask.

Installing it

The installer takes the address people will open and the email of the first account:

Shell
sudo bash install.sh https://mail.example.com you@example.com
  1. It installs Caddy, which serves https and renews the certificate, and Bun, which runs the server.
  2. It makes a user for the server to run as, and its folders.
  3. It writes the settings with a new secret, and a service that starts with the machine.
  4. It asks for the password of the first account, then starts everything.

On a host that takes user data, such as Hetzner or DigitalOcean, the same installer runs by itself when the server starts for the first time. A first boot cannot ask for a password, so one command afterwards makes your account:

Shell
ssh -t root@<server> opensend-server owner you@example.com

Not released yet. The server is not published as a package, and the installer has only run on a development machine. The self-hosting guide is the place to check what is ready.

How the mail leaves

Way
With Nextmail
What sends
Nextmail sends with a key of your account there, and your server keeps the data
What it costs
What Nextmail charges for the mail you send
Ready
Yes
Way
Your own engine
What sends
The sending engine runs inside the server, signs with DKIM, delivers from your address and receives on port 25
What it costs
Nothing beyond the server
Ready
Written, not released

The first way is one setting, NEXTMAIL_API_KEY. Without it, and without the engine, the console says sending is not connected and nothing is sent. Nothing is faked to look complete. What Nextmail is has its own post.

Who gets in

  • The account made at install owns the server. It signs in with an email and a password, because a new server cannot email a code yet.
  • Sign-ups are closed. People come in by invitation, and while the server sends no mail you copy the link of an invitation and send it yourself.
  • A workspace has the limits you set for the server and none where you set none.

Upkeep

Shell
opensend-server statusopensend-server logsopensend-server restartopensend-server upgrade
  • To back it up, stop the service and copy the one folder.
  • To upgrade, run one command. A new version applies its own changes to the database when it starts.
  • For a forgotten password there is a command on the server. Nothing is recovered by email until the server sends email.

Should you host it yourself?

  • Yes, if your data has to stay on machines you control, or if a server costs you less than a subscription and someone on the team looks after servers anyway.
  • No, if nobody wants to be woken by a full disk. Our cloud runs the same code.

And if you deliver from your own address one day: a new address has no reputation with the large mail providers, so start with small volumes and let it grow.

The self-hosting page has every setting a server reads.

Sources

  1. cloud-init documentation, cloud-init
  2. Caddy, Caddy
  3. Bun, Bun
  4. SQLite, SQLite

More from the blog

Send your first email in a few minutes.

Create a key and send, or clone the repository and run it yourself.