This page details the process of installing and configuring a functional cmail server. Please note that running your own email server is a nontrivial commitment to keeping that service up and running in order to allow people to reach you. It may be useful to run at least two physically separate mail servers for redundancy.
Depending on your experience and requirements, this may either be the first step to perform (if you are configuring a fresh domain) or the last (if you are moving an existing domain or already are experienced with running mail servers).
In order to announce to the rest of the world that any particular server on the internet should receive mail for a domain, that domain needs to have a so-called MX record in its DNS table. The server responsible for your domains DNS is most often configurable by some kind of panel at your registrar.
An MX record contains the IP addresses or hostnames of one or more servers that will be connected to by other mail servers trying to send you mail. These records are ordered, so that if one of them should fail another one is automatically tried.
In order to properly receive mail adressed to your domain, you will have to set up these records to point at the machine running your upcoming cmail installation.
Install the package with your package manager of choice (eg. dpkg, pacman). Depending on the package maintainer, this process may already run a dialog of some sorts querying basic configuration information.
We're going to assume the system already sports a working C compiler as well as the git version control system. First, we're going to install the build prerequisites.
~# apt-get install libsqlite3-dev nettle-dev libgnutls28-dev libadns1-dev
Additionally, we're going to install some tools needed for initial setup operations.
~# apt-get install sqlite3
~# apt-get install openssl
Next, we'll clone the cmail repository to the disk
~# git clone https://github.com/cmail-mta/cmail
In the cloned directory, run make
to build all modules, followed
by make install
to copy the binaries to a system path (by default
/usr/sbin/
, this may be changed by supplying the environment variable
PREFIX
). The system documentation, available with
man <component>
is installed by running
make install-doc
.
Running make init
after this step will create a
new user for cmail (in order to minimize attack surface, cmail is not usually run as root
and instead drops its privileges after initialization), copy over default configuration files,
correctly set privileges and generally set up the basic structure needed for operation.
Alternatively, the make tls-init
command does all that and also generates a temporary TLS
certificate and key for initial usage and testing (openssl required). Please remember to replace the
generated key and certificate with secure ones when using this option.
~# cd cmail
~/cmail# make
~/cmail# make install
~/cmail# make install-doc
~/cmail# make tls-init
Advanced users may specify some parameters to the makefile install process via environment variables. Currently, these are:
PREFIX |
Installation prefix |
DOCDIR |
Path to install generated manpages to |
LOGDIR |
Path to store logfiles |
CONFDIR |
Path for configuration files |
DBDIR |
Path for master database file |
BANNER |
Announce banner |
After these steps, the core cmail binaries as well as the administration tool suite will have been installed. Should you prefer using the web administration interface to the command line tools, the HTTP API and web panel need to be installed additionally.
In order to have cmail start up at boot time, your init system may need specific files (such as service files
or init scripts). Example files are provided in startup-scripts/
for systemd and sysvinit.
Check the documentation for your system to find out how to install these files.
/etc/cmail/
. Read them carefully to verify
the system is configured the way you want it.
If your setup method did not automatically create the configuration files for you (or you did not want to use
the provided setup mechanisms), you may also copy over example configuration files to modify from the
example-configs/
folder in the repository.
Make sure to check the announce
parameters to the bind
directives.
Most install processes will set those to your current hostname.
Also make sure to replace the TLS key material generated by make tls-init
with properly
signed and trusted keys.
To do this, run the daemons one by one without having them detach from the console, so you can
see their debug information printed. After verifying that the configuration works, exit the daemons
again by pressing Ctrl-C
.
~# cmail-smtpd nodetach /etc/cmail/smtpd.conf
~# cmail-popd nodetach /etc/cmail/popd.conf
~# cmail-dispatchd nodetach /etc/cmail/dispatchd.conf
After this step, you may want to turn down the verbosity of the cmail services so they do not
log as much information as they would by default. This can be done by decreasing the
verbosity
parameter in the configuration files.
~# ss -lt
~# lsof | grep TCP
~# apt-get uninstall exim4*
~# tcptraceroute your-server 25
~# gnutls-cli --starttls --insecure --crlf --port <port> <host>
tlsonly
ports you may need to press Ctrl-D
once to
start TLS negotiation. A second Ctrl-D
will close the connection.
swaks
is a tool used for testing mail server operation by simply sending
test mails. Run the tool from another host with
~# swaks --from foo@bar.baz --to <recipient> --server <host>
~# ss -lt
~# iptables -L -v