Skip to content

Instantly share code, notes, and snippets.

@jfstenuit
Created July 10, 2024 07:57
Show Gist options
  • Save jfstenuit/660180f89e00b1a09b4e98db5f6782da to your computer and use it in GitHub Desktop.
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.

Steps

1. Install ssmtp and bsd-mailx

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

sudo apt update
sudo apt install ssmtp bsd-mailx

2. Configure ssmtp

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

3. Configure revaliases

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

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