Skip to content

Instantly share code, notes, and snippets.

@jfstenuit
Last active January 6, 2026 10:41
Show Gist options
  • Select an option

  • Save jfstenuit/660180f89e00b1a09b4e98db5f6782da to your computer and use it in GitHub Desktop.

Select an option

Save jfstenuit/660180f89e00b1a09b4e98db5f6782da to your computer and use it in GitHub Desktop.
Minimal mail service for debian-based systems

Minimal Mail Configuration for Debian-Based Servers

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.

Steps

1. Install msmtp and bsd-mailx

First, update the package lists and install the required packages:

sudo apt update
sudo apt install msmtp msmtp-mta bsd-mailx

2. Configure msmtp

Edit 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

3. Create log file /var/log/msmtp.log and ensure everything has the proper permissions

touch /var/log/msmtp.log
chown root:msmtp /etc/msmtprc /var/log/msmtp.log
chmod 640 /etc/msmtprc /var/log/msmtp.log

4. Alter /etc/passwd to identify the server in the Gecos field

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

5. Testing the Configuration

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment