By default your Debian server will try to deliver system / Cron emails to your mailbox server directly. While this is convenient for very simple setups, you might run into trouble if your inbox server expects DKIM-signed mails or does not accept emails from every IP address, but only from mail senders with good reputation. For that reason I’m running a single, well configured email gateway server, which is forwarding the mails from all my hosts into the internet. But how to tell all the hosts to send their mails via a central gateway? Installing and configuring Postfix is one way …
… but there’s a much cheaper alternative: The msmtp client.
While Postfix is way overpowered for such simple tasks, msmtp is the perfect tool for the job: It is a Sendmail compatible mail client, which does nothing but forwarding mail to the gateway.
msmtp-mta from the official Debian repositories (not to be confused with msmtpd!):
apt install msmtp-mta
… and create a new system-wide config file
account default aliases /etc/aliases host gateway.mydomain.tld auto_from on domain myhost01.mydomain.tld maildomain myhost01.mydomain.tld tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt syslog LOG_MAIL
myhost01.mydomain.tldis the host name of the system that uses msmtp (web server, application server, … )
gateway.mydomain.tldis the FQDN of the central email gateway, running e.g. a full featured Postfix instance
That’s it! If you’re interested in tweaking your configuration and finding out more, have a look at the example config at
Just one more thing: Usually you want to have all the mail to all system users forwarded to an administrative account. In my case the admin account is
email@example.com. In that case, change
You will receive all emails in that mailbox, now. To check your settings, issue an example mail from your
apt install bsd-mailx echo "This is a test mail" | mail -s "Testmail" root