2023-08-30 — 2 min read

Setting up email notifications with mailx (S-nail) and Fastmail

This is just a quick note regarding the setup of email notifications for S.M.A.R.T. errors on a Linux box, using S-nail to send the messages through the Fastmail SMTP server.

On my home computer, I don’t want to use a full-fledged MTA but I would still like to send notification emails when various error conditions occur, for instance in cases of S.M.A.R.T. errors. Delivering these emails through an external SMTP server is probably the most straightforward solution. There are many posts about setting it up with Gmail but I haven’t found one for Fastmail, hence this note. The following is for Arch Linux, but the setup should be very similar for other distributions as well.

We will need the above-mentioned S-nail package for this task, it will communicate with the remote SMTP server to deliver our messages. Its configuration file is /etc/mail.rc or $HOME/.mailrc – I went with the one in /etc since it will only be used to send systemwide notifications. For this simple case, we will only need to add two lines to the default configuration:

set v15-compat
set mta=submissions://USER:[email protected]:465

The v15-compat line is needed so we can use the submissions protocol in the next line. This protocol means that the SMTP server supports RFC 8314, which Fastmail does. We will also need to explicitly specify the port, according to the manual

Regarding the USER and PASS parameters: the USER is our Fastmail username (including the domain), and the PASS is an app password we will need to generate by following the above tutorial.

We can optionally add a third line to /etc/mail.rc to set the default FROM address of the notification emails:

set from="Your Name <[email protected]>"

Once the setup is done, we can test it with a command similar to this (the email address at the end of the line should be changed to the actual recipient):

# echo "Sample Body" | mailx --verbose --verbose --subject "Sample Subject" [email protected]

If we set the parameters right, it should work without any issues.

As for the S.M.A.R.T. notifications, simply add a line similar to this to /etc/smartd.conf:

DEVICESCAN -a -o on -S on -n standby,q -s (S/../.././02|L/../../6/03) -W 4,35,40 -m example@example.com -M test

The last bit (-M test) could be left off, I added it so that every time I restart the daemon I get a test email, this way I can check whether the email sending still works.

Thanks for reading! If you have any comments, additions, or corrections, feel free to reach me via e-mail.

Copyright © 2023 csm.hu
Contact