Skip to the page

Self-hosting

Run OpenSend on a server of your own: the dashboard, this API and the database in one program, with a sending engine underneath or Nextmail behind it.

What you run

Not released yet. The server and the engine are not published as packages, and the installer has only been tried on a development machine. Read this page as a preview of what is built.

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

Way
Your own engine
What sends
The engine in @nextmail/engine starts inside the server. It signs with DKIM, delivers from your address and receives on port 25
What it costs
Nothing beyond the server
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

The code is the same whoever hosts it, so every page of these docs holds on your server too. What differs is listed at the end of this page.

What you need

  • A server with Debian or Ubuntu and root access. The installer is written for those two.
  • 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.
  • For your own engine: port 25 open in both directions, and a PTR record that names the server for its address. Many hosting companies keep port 25 closed on a new account until you ask them.

Install 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 named opensend for the server to run as, and its folders.
  3. It installs the server and the engine.
  4. It writes the settings with a new secret, a service that starts with the machine, and the proxy entry.
  5. It asks for the password of the first account, then starts everything.

Open the address and sign in with that email and password. On any other machine with Bun, the same can be done by hand: two settings are required, and the server then listens on 127.0.0.1:3000 behind a proxy of your choice.

Shell
bun add @open-send/opensend-server @nextmail/engine export SERVER_URL=https://mail.example.comexport AUTH_SECRET="$(openssl rand -hex 32)" bunx opensend-server owner you@example.combunx opensend-server start

On a cloud server

A host that takes user data, such as Hetzner or DigitalOcean, can run the installer by itself when the server starts for the first time. cloud-init.sh is the same installer with your address on its third line, so it takes no arguments.

  1. Change the address on line 3 of cloud-init.sh.
  2. Create the server with that file as its user data, in the form of the host or with its tool.
  3. Point the name at the server. The certificate arrives by itself once the name resolves.
  4. Make the first account from a terminal. A first boot cannot ask for a password, so this one step is yours.
Shell
hcloud server create --name mail --type <type> --image <image> --ssh-key <key> --user-data-from-file cloud-init.shdoctl compute droplet create mail --image <image> --size <size> --ssh-keys <key> --user-data-file cloud-init.sh
Shell
ssh -t root@<server> opensend-server owner you@example.com

What happened at the first boot is in /var/log/cloud-init-output.log on the server. The server needs an IPv4 address, because the runtime is downloaded from a host that has no IPv6.

Run and upgrade it

Shell
opensend-server statusopensend-server logsopensend-server restartopensend-server upgrade
Command
status, logs
What it does
Shows whether the service runs, or follows what it writes
Command
start, stop, restart
What it does
Controls the service
Command
upgrade
What it does
Installs the newest server and engine, then restarts
Command
owner <email>
What it does
Makes the account that owns the server. For an account that exists, it hands the server to that account
Command
password <email>
What it does
Gives an account a new password and signs it out everywhere

Everything the server stores is under SERVER_DATA_DIR, which the installer sets to the opensend folder in /var/lib. Stop the service and copy that folder to back it up. The migrations of a new version run by themselves when it starts.

Settings

The settings are environment variables. The installer keeps them in server.env, in the opensend folder of /etc, where only root reads them. Restart after a change.

Name
SERVER_URL
Default
Required
What it is
The address people open
Name
AUTH_SECRET
Default
Required
What it is
At least 32 characters, made once and never changed. It signs every session
Name
SERVER_HOST, SERVER_PORT
Default
127.0.0.1, 3000
What it is
Where it listens, behind the proxy
Name
SERVER_DATA_DIR
Default
data
What it is
The folder for the database, the files and the engine
Name
SERVER_ENGINE
Default
on
What it is
off never starts the engine
Name
NEXTMAIL_API_KEY
Default
None
What it is
A key of your Nextmail account. With it the server sends through Nextmail and the engine stays off
Name
MAIL_FROM
Default
None
What it is
The sender of the server's own mail: sign-in codes and invitations
Name
SUPPORT_EMAIL
Default
None
What it is
Where an answer to the server's own mail goes, and where the contact form of the site sends a message
Name
TURNSTILE_SITE_KEY, TURNSTILE_SECRET_KEY
Default
None
What it is
The two keys of a Cloudflare Turnstile widget made for your address. With both set, asking for a sign-in code needs a passed check
Name
SERVER_SIGN_UPS
Default
closed
What it is
What a new server starts with: open or closed
Name
SERVER_PLAN_LIMITS
Default
None
What it is
The limits a new server starts with, as name=number pairs such as members=10, domains=5

The last two only give a new server its first values. Once the owner changes them in the dashboard, the dashboard holds them, and the server says in its log at every start that the file no longer applies.

Who gets in

The account made at install owns the server. It signs in with its email and password, because a new server cannot email a code yet.

  • Sign-ups are closed, so people come in by invitation. Invite someone under Settings, Team.
  • While the server sends no mail, copy the link beside the invitation and send it yourself. The person opens it, chooses a password and joins. A link works once and for seven days, sending the invitation again replaces it, and only the owner of the server is shown it.
  • To let anybody make an account, switch on Open sign-ups under Settings, Server. A new person signs in with an emailed code, so the server has to send mail first.
  • Everyone changes their own password on their profile page. For a forgotten one, run opensend-server password <email> on the server.

The server settings are read and changed through the API too. Only the owner changes them, signed in: a key belongs to one workspace, and these settings govern all of them.

Limits

A workspace on your server is on the self_hosted plan. It has the limits you set and none where you set none. Set them under Settings, Server. A change applies at once to every workspace, the ones that exist already included.

Limit
transactional
What it counts
Emails sent in a month through the API and automations
At the limit
Sending is refused
Limit
marketing
What it counts
Emails sent in a month as broadcasts
At the limit
Broadcasts wait for the next month
Limit
contacts
What it counts
Contacts held
At the limit
No more can be added
Limit
domains
What it counts
Domains added
At the limit
No more can be added
Limit
members
What it counts
People, waiting invitations included
At the limit
No more can be invited

Received emails and API requests are counted too, and nothing stops at a number for them.

Send and receive

  1. Add your domain in the dashboard and publish the DNS records it shows. Domains explains each one.
  2. Give the address of the server a PTR record that names it, and check that port 25 is open both ways.
  3. Send a first email from the dashboard or the API, and watch it arrive.
  4. Set MAIL_FROM to an address on that domain and restart. From then on the server emails sign-in codes and invitations by itself.
Shell
MAIL_FROM="Acme <hello@mail.example.com>"

To send through Nextmail instead, set NEXTMAIL_API_KEY and add the domain the same way. The records are then the ones Nextmail asks for.

What is different on your server

  • There are no plans to buy. Every workspace is on the self_hosted plan with the limits its server sets.
  • The examples in these docs name our cloud. On your server the address is your own SERVER_URL: set OPENSEND_API_URL to it, or give the client baseUrl.
  • An account made at install, or through an invitation link, signs in with a password. The hosted product has no passwords.
  • Delivery is yours to earn: a new address has no reputation with the large mail providers, so start with small volumes.