How to Install MailTrain App on Ubuntu or Debian
In this quick guide you’ll learn how to get the MailTrain email client up and running on a fresh Ubuntu or Debian box in under 30 minutes. It covers both the Docker‑based approach (the easiest way) and the classic “apt + systemd” method if you prefer not to touch containers.
Quick tip: If you’re using an older LTS release like Bionic, just skip the “Upgrade PHP” step—MailTrain’s official image already bundles a recent PHP version.
Prerequisites
- A machine running Ubuntu 20.04/22.04 or Debian 10/11 with root privileges.
- curl and git installed (most distros come with them).
- An email server ready to accept connections; MailTrain will use whatever IMAP/SMTP you point it at.
Step 1: Update the System
sudo apt update && sudo apt upgrade -y
A fresh kernel and security patches keep your container runtime safe. I’ve seen a whole batch of users hit “unable to pull image” errors after an outdated libc package.
Step 2: Install Docker (if you don’t have it)
sudo apt install -y docker.io docker-compose sudo systemctl enable --now docker
Docker is the sweet spot for MailTrain because all dependencies are bundled. If you’re on a minimal server, the container will be lighter than installing PHP, MySQL, and Nginx manually.
Step 3: Pull the Latest MailTrain Image
docker pull mailtrain/mailtrain:latest
The image includes PHP 8.x, a built‑in web server, and the full Roundcube stack. You won’t need to juggle package versions yourself.
Step 4: Create a Configuration File
MailTrain expects a config.ini with database credentials and mail settings. Here’s a minimal example:
# config.ini [database] type = mysql host = db.example.com user = mailtrain_user pass = supersecret name = mailtrain_db [imap] host = imap.example.com port = 993 ssl = true username = yourmail@example.com password = mymailpassword
Why a separate file? It keeps secrets out of the Docker command line and lets you tweak settings without rebuilding images.
Step 5: Run MailTrain
docker run -d \ --name mailtrain \ -p 8080:80 \ -v $(pwd)/config.ini:/usr/share/nginx/html/config.ini \ mailtrain/mailtrain:latest
- -d runs it in the background.
- -p 8080:80 exposes it on port 8080; change if you’re already using 80/443.
- Mounting the config file gives the container read access to your settings.
Open a browser to http://your-server-ip:8080. If you see MailTrain’s login screen, congrats—you’ve got yourself a self‑hosted webmail stack.
Step 6 (Optional): Use Docker Compose
If you want an easier way to manage the container, create a docker-compose.yml:
version: "3.8"
services:
mailtrain:
image: mailtrain/mailtrain:latest
ports:
- "8080:80"
volumes:
- ./config.ini:/usr/share/nginx/html/config.ini
restart: unless-stopped
Then just:
docker compose up -d
Step 7: Secure the Connection (HTTPS)
If you’re on a public IP, grab a Let’s Encrypt cert:
sudo apt install -y certbot python3-certbot-nginx certbot --nginx -d mail.example.com
Or if you prefer a self‑signed cert for an intranet setup, generate one with openssl and point Nginx to it.
Troubleshooting
| Symptom | Likely Cause | Fix |
|---|---|---|
| “Could not resolve host” | DNS misconfigured in config.ini | Double‑check the hostname or use an IP address. |
| Container crashes on start | Missing environment variables | Add them as -e VAR=value flags or update config.ini. |
| MailTrain loads but no messages show | IMAP credentials wrong | Verify username/password against your mail server. |
I’ve seen users forget to expose the IMAP port, so always make sure the server you’re pointing at is reachable from the container (try docker exec -it mailtrain ping imap.example.com).
Clean Up
If you ever need to remove MailTrain:
docker stop mailtrain && docker rm mailtrain
Delete the image if you’re tight on disk space:
docker rmi mailtrain/mailtrain:latest
That’s all there is to it. No more “I can’t get this webmail thing working” headaches—just a single Docker run and you’re ready to send and receive mail from your own server.