User Tools

Site Tools


Sending custom notification emails

The purpose of this guide is to set up the mail software installed on your Turris Omnia to send various notification emails via the email servers provided by turris.cz. When configured to send mail to the root user, the various services you have running on your Turris (e.g. the mdadm RAID tool) will deliver important messages directly on your personal email (e.g. your RAID array is degraded). All the operations described in this guide will be performed via the SSH interface.

This guide is not about setting your own mail server (why go through the trouble when Turris kindly makes one available to the community?). This guide also does not explain how to set up each software to notify root because it is software-dependent.

Configuring the mail server

The mail-user agent (MUA) and SMTP software called msmtp is already installed on the Turris Omnia and used by the notifier script (/usr/bin/notifier) to issue email notifications when the router receives updates. It is compatible with sendmail, and in fact replaces it on the Turris Omnia, as shown by the output of this command:

$ ls -al /usr/sbin/sendmail 
lrwxrwxrwx    1 root     root            12 Oct 20  1969 /usr/sbin/sendmail -> ../bin/msmtp

The notifier script provides all the information needed to configure msmtp by generating and providing a configuration file that look like this (depending on your configuration parameters in the Foris interface):

account notifier
from turris@notify.turris.cz
host smtp.turris.cz
port 465
tls on
tls_certcheck off
tls_starttls off
auth on
user XXXXXXXXXXX
password XXXXXXXXXXX
timeout 5
account default: notifier

The username and password (shown as XXXXXXXXXXX above) are router-dependent.

Edit the msmtp configuration file at /etc/msmtprc to add a default account. I kept the “account default” and “syslog LOG_MAIL” directives from the default configuration file and replaced the rest by the content given previously.

Note: after experimenting with msmtp at end of February 2017 I did find that either there are account commands at the beginning of /etc/msmtprc in the form “account notifier” and near to the end of file as “account default : notifier”, or there is only command “account notifier” or “account default” at the beginning of /etc/msmtprc, without second account command for this simple case.

Replace the username (line starting with “user” above) by the result of the command:

$ atsha204cmd serial-number

Replace the “password” line by the this directive, which will avoid storing the password in clear:

passwordeval "echo 'efefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefef' | atsha204cmd challenge-response | awk '{print tolower($0)}'"

Refer to the msmtp documentation for a description of the various configuration options.

Now, send a test email using the command (use an actual email address!):

$ echo "Hello world!" | msmtp --debug my.email@domain.com

Redirecting root emails

Now that we can send emails, make sure that every email that is sent to the “root” user (e.g. by mdadm) is forwarded to your actual email box.

Create a file called /etc/aliases with this content:

root: my.email@domain.com

You can add several comma-separated email addresses instead of single one.

Add the following line to your /etc/msmtprc config file:

aliases /etc/aliases

Send a test email to root (you should now receive it on the email address you specified above):

$ echo "Hello world!" | msmtp --debug root

Note there is missing Subject header in mail configured and sent as above… if you want to add it change mail command like following:

$ echo -e "Subject: Hello\n\nHello world!" | msmtp --debug root

Enjoy! 8-)