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.
First, update the package lists and install the required packages:
sudo apt update
sudo apt install ssmtp bsd-mailx
Edit the ssmtp configuration file /etc/ssmtp/ssmtp.conf with the following content. You will need to adjust the settings according to your smarthost (SMTP server) details:
# /etc/ssmtp/ssmtp.conf
[email protected]
mailhub=smtp.example.com:587
AuthUser=your_smtp_username
AuthPass=your_smtp_password
UseTLS=YES
UseSTARTTLS=YES
hostname=your_server_hostname
# Where will the mail seem to come from?
rewriteDomain=example.com
# The full hostname
hostname=your_server_hostname
Edit the ssmtp
aliases file /etc/ssmtp/revaliases
to map local users to their email addresses:
# /etc/ssmtp/revaliases
root:[email protected]:smtp.example.com:587
username:[email protected]:smtp.example.com:587
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]