This guide provides the steps to configure minimal mail capacity on Debian-based servers to enable sending mail notifications to a sysadmin through a smarthost MTA.
Previous version of this document used to document installation of ssmtp , which is now recognized as unmaintained/obsolete.
First, update the package lists and install the required packages:
sudo apt update
sudo apt install msmtp msmtp-mta bsd-mailxEdit the msmtp configuration file /etc/msmtprc with the following content. You will need to adjust the settings according to your smarthost (SMTP server) details:
# /etc/msmtprc
# owner: root:msmtp
# mode: 0640
defaults
logfile /var/log/msmtp.log
account local-relay
host smtp.example.com
port 25
auth off
tls off
from [email protected]
account default : local-relay
aliases /etc/aliases
touch /var/log/msmtp.log
chown root:msmtp /etc/msmtprc /var/log/msmtp.log
chmod 640 /etc/msmtprc /var/log/msmtp.log
Edit the /etc/passwd file and update the Gecos field (the fifth field) to include the server identifier. This helps in identifying the server when emails are received. The format of a typical line in /etc/passwd is:
username:x:uid:gid:Gecos field:/home/username:/bin/bash
For example, if your server's identifier is Server01, the entry might look like:
root:x:0:0:Server01 Admin:/root:/bin/bash
your_username:x:1000:1000:Server01 User,,,:/home/your_username:/bin/bash
After configuring, test the setup by sending a test email:
echo "This is a test email from your server" | mail -s "Test Email" [email protected]