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.
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:
$ echo "$(crypto-wrapper serial-number)@notify.turris.cz"
Password is for the notifier stored in file at /etc/sentinel/mailpass
so instead of password
we can use passwordeval
like:
passwordeval "cat /etc/sentinel/mailpass"
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
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!
To avoid misuse of service to send spam the number of messages is limited to approx. 10/day (https://forum.turris.cz/t/sending-mail-via-msmtp/5650). After reaching the limit the SMTP server will start refusing the email. If it affects you, turn to an alternative SMTP provider.
Vixie's cron (default in TO) expects mail program to be in /usr/lib/sendmail
hence a symbolic link will fix this:
$ ln -sf /usr/sbin/sendmail /usr/lib/sendmail