By default, system emails are sent to the local root account. These emails can provide alerts and tips on the system health. This guide help you setup a redirection to an external email address (sysadmin’s one) for these emails.

This howto is tested on:

  • Debian 10.0 Buster

Settings

Set the external email address to which system emails are sent:

sysadminEmail="account@gmail.com"

Installation

Detect if sudo is available (“command” is used if not):

cmdProxy='command'
command type -f 'sudo' &>'/dev/null' && cmdProxy='sudo'

SMTP server setup

Install the required software:

${cmdProxy} apt install 'exim4' 'bsd-mailx'

Use the current full hostname as the system mail domain (best default for a commercial dedicated server):

command hostname --fqdn \
    | ${cmdProxy} tee '/etc/mailname'

Setup the Exim 4 SMTP server as directly connected to the Internet (no relay SMTP used):

${cmdProxy} sed -i \
    -e "s|dc_eximconfig_configtype=.*\$|dc_eximconfig_configtype='internet'|" \
    -e "s|dc_other_hostnames=.*\$|dc_other_hostnames='$(command hostname --fqdn)'|" \
    -e "s|dc_use_split_config=.*\$|dc_use_split_config='true'|" \
  '/etc/exim4/update-exim4.conf.conf'

Update Exim 4 configuration:

${cmdProxy} update-exim4.conf

Reload Exim 4 configuration:

${cmdProxy} systemctl restart 'exim4'

System emails redirection

Redirect emails sent to the local root account to the chosen email address:

${cmdProxy} sed -i \
    -e "s/^root:.*\$/root: ${sysadminEmail}/" \
  '/etc/aliases'

Reload the email aliases configuration:

${cmdProxy} newaliases
Categories: Setup

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.