SMART Disk Monitoring and Email Alerts with msmtp + smartd (Ubuntu Server)

This guide explains how to:

  • monitor disk SMART status,
  • run automatic SMART self-tests,
  • receive email alerts,
  • integrate smartd with msmtp,
  • use your own SMTP server.

Suitable for:

  • Ubuntu Server 22/24,
  • NAS systems,
  • home servers,
  • mini-PC,
  • KVM/Proxmox hosts.

1. Install msmtp

sudo apt update && sudo apt upgrade -y
sudo apt install msmtp -y

2. Configure SMTP (Example configuration):

sudo nano /etc/msmtprc
defaults
auth           on
tls            on
tls_starttls   on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account        external
host           mx2.itbumper.com
port           587

from           inventory@itbumper.com
user           inventory@itbumper.com
password       your_password

account default : external
sudo chmod 600 /etc/msmtprc
sudo chown root:root /etc/msmtprc

3. Test email sending

echo -e "Subject: Test\n\nHi, connection test!" | sudo msmtp --debug radik.m@itbumper.com
loaded system configuration file /etc/msmtprc
ignoring user configuration file /root/.msmtprc: No such file or directory
falling back to default account
using account default from /etc/msmtprc
host = mx2.itbumper.com
port = 587
source ip = (not set)
proxy host = (not set)
proxy port = 0
socket = (not set)
timeout = off
protocol = smtp
domain = localhost
auth = choose
user = inventory@itbumper.com
password = *
passwordeval = (not set)
ntlmdomain = (not set)
tls = on
tls_starttls = on
tls_trust_file = /etc/ssl/certs/ca-certificates.crt
tls_crl_file = (not set)
tls_fingerprint = (not set)
tls_key_file = (not set)
tls_cert_file = (not set)
tls_certcheck = on
tls_min_dh_prime_bits = (not set)
tls_priorities = (not set)
tls_host_override = (not set)
auto_from = off
maildomain = (not set)
from = inventory@itbumper.com
from_full_name = (not set)
allow_from_override = on
set_from_header = auto
set_date_header = auto
remove_bcc_headers = on
undisclosed_recipients = off
dsn_notify = (not set)
dsn_return = (not set)
logfile = (not set)
logfile_time_format = (not set)
syslog = (not set)
aliases = (not set)
reading recipients from the command line
<-- 220 mx2.itbumper.com ESMTP Postfix
--> EHLO localhost
<-- 250-mx2.itbumper.com
<-- 250-PIPELINING
<-- 250-SIZE 157286400
<-- 250-ETRN
<-- 250-STARTTLS
<-- 250-ENHANCEDSTATUSCODES
<-- 250-8BITMIME
<-- 250 DSN
--> STARTTLS
<-- 220 2.0.0 Ready to start TLS
TLS session parameters:
    (TLS1.3)-(ECDHE-SECP256R1)-(RSA-PSS-RSAE-SHA256)-(AES-256-GCM)
TLS certificate information:
    Subject:
        CN=mx2.itbumper.com
    Issuer:
        C=US,O=Let's Encrypt,CN=R13
    Validity:
        Activation time: Wed 06 May 2026 06:12:03 AM PDT
        Expiration time: Tue 04 Aug 2026 06:12:02 AM PDT
    Fingerprints:
        SHA256: DC:73:D5:D9:39:92:2D:A4:EF:E0:62:A2:91:F1:1B:5D:38:46:53:38:85:25:DE:90:7C:4F:03:96:8C:B0:6F:5B
        SHA1 (deprecated): 77:9D:65:82:C3:4A:FD:31:F2:0F:F2:E0:85:12:DC:3A:26:CB:5E:8F
--> EHLO localhost
<-- 250-mx2.itbumper.com
<-- 250-PIPELINING
<-- 250-SIZE 157286400
<-- 250-ETRN
<-- 250-AUTH PLAIN LOGIN
<-- 250-ENHANCEDSTATUSCODES
<-- 250-8BITMIME
<-- 250 DSN
--> AUTH PLAIN AGludmVudG9yeUBpdGJ1bXBlci5jb20AaXBELlIxIUhrSTY9TzJ0bndeR3I=))
<-- 235 2.7.0 Authentication successful
--> MAIL FROM:<inventory@itbumper.com>
--> RCPT TO:<radik.m@itbumper.com>
--> DATA
<-- 250 2.1.0 Ok
<-- 250 2.1.5 Ok
<-- 354 End data with <CR><LF>.<CR><LF>
--> From: inventory@itbumper.com
--> Date: Thu, 21 May 2026 23:41:58 -0700
--> Message-ID: <f64123ba223eabf36d2f4302ce54a29b.inventory@itbumper.com>
--> Subject: Test
-->
--> Hi, connection test!
--> .
<-- 250 2.0.0 Ok: queued as 4gMG0V0cnhzqXKf
--> QUIT
<-- 221 2.0.0 Bye

4. Check smartd service and enable if needed:

systemctl status smartd
sudo systemctl enable --now smartd

5. Create smartd mailer script

sudo nano /usr/local/bin/smartd-mailer
#!/bin/bash

EMAIL="radik.m@itbumper.com"

(
echo "To: $EMAIL"
echo "From: inventory@itbumper.com"
echo "Subject: ITB HOST-01 SMART Alert"
echo
cat
) | /usr/bin/msmtp "$EMAIL"
sudo chmod 755 /usr/local/bin/smartd-mailer

6. Configure smartd

sudo nano /etc/smartd.conf

only ONE configuration line should be active:

  • either TEST mode,
  • or WORK mode.

Do not leave both entries enabled at the same time.

#EXAMPLE
# WORK mode disabled during testing
#DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -m radik.m@itbumper.com -M exec /usr/local/bin/smartd-mailer

# TEST mode enabled
DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -M test -m radik.m@itbumper.com -M exec /usr/local/bin/smartd-mailer

# -M test
#parameter forces smartd to immediately send a test alert after service startup.
#This validates:
#  smartd functionality,
#  mailer script execution,
#  msmtp operation,
#  SMTP authentication,
#  email delivery.

6. Schedule format:  T/MM/DD/d/HH

Where:

Field Meaning
T Test type
S Short test
L Long test
MM Month
DD Day of month
d Day of week
HH Hour

Example schedule: (S/../.././02|L/../../6/03):

  • Short test daily at 02:00
  • Long test every Saturday at 03:00

Restart services

sudo systemctl restart smartd

Expected Result If configured correctly:

  • a SMART test email should arrive,
  • no smartd errors should appear,
  • msmtp should successfully deliver the message.

After receiving the test email:

  1. Disable TEST entry
  2. Enable WORK entry
  3. Save the file
  4. Restart smartd
# TEST mode disabled
#DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -M test -m radik.m@itbumper.com -M exec /usr/local/bin/smartd-mailer

# WORK mode enabled
DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -m radik.m@itbumper.com -M exec /usr/local/bin/smartd-mailer

Verify SMART Test Schedule

sudo smartd -q showtests
#Example
smartd 7.4 2023-08-01 r5530 [x86_64-linux-6.8.0-111-generic] (local build)
Copyright (C) 2002-23, Bruce Allen, Christian Franke, www.smartmontools.org

Opened configuration file /etc/smartd.conf
Configuration file /etc/smartd.conf was parsed, found DEVICESCAN, scanning devices
Device: /dev/sda, type changed from 'scsi' to 'sat'
Device: /dev/sda [SAT], opened
Device: /dev/sda [SAT], Samsung SSD 860 PRO 1TB, S/N:S5G8NS0NB01379X, WWN:5-002538-e30b0d388, FW:RVM02B6Q, 1.02 TB
Device: /dev/sda [SAT], found in smartd database 7.3/5528: Samsung based SSDs
Device: /dev/sda [SAT], enabled SMART Attribute Autosave.
Device: /dev/sda [SAT], can't monitor Current_Pending_Sector count - no Attribute 197
Device: /dev/sda [SAT], can't monitor Offline_Uncorrectable count - no Attribute 198
Device: /dev/sda [SAT], enabled SMART Automatic Offline Testing.
Device: /dev/sda [SAT], is SMART capable. Adding to "monitor" list.
Device: /dev/sda [SAT], state read from /var/lib/smartmontools/smartd.Samsung_SSD_860_PRO_1TB-S5G8NS0NB01379X.ata.state
Device: /dev/sdb, type changed from 'scsi' to 'sat'
Device: /dev/sdb [SAT], opened
Device: /dev/sdb [SAT], Samsung SSD 860 PRO 1TB, S/N:S5G8NS0NB00206K, WWN:5-002538-e30b0cef3, FW:RVM02B6Q, 1.02 TB
Device: /dev/sdb [SAT], found in smartd database 7.3/5528: Samsung based SSDs
Device: /dev/sdb [SAT], enabled SMART Attribute Autosave.
Device: /dev/sdb [SAT], can't monitor Current_Pending_Sector count - no Attribute 197
Device: /dev/sdb [SAT], can't monitor Offline_Uncorrectable count - no Attribute 198
Device: /dev/sdb [SAT], enabled SMART Automatic Offline Testing.
Device: /dev/sdb [SAT], is SMART capable. Adding to "monitor" list.
Device: /dev/sdb [SAT], state read from /var/lib/smartmontools/smartd.Samsung_SSD_860_PRO_1TB-S5G8NS0NB00206K.ata.state
Device: /dev/sdc, type changed from 'scsi' to 'sat'
Device: /dev/sdc [SAT], opened
Device: /dev/sdc [SAT], TOSHIBA HDWE140, S/N:708BK08NFBRG, WWN:5-000039-a2bc00405, FW:FP1R, 4.00 TB
Device: /dev/sdc [SAT], found in smartd database 7.3/5528: Toshiba X300
Device: /dev/sdc [SAT], enabled SMART Attribute Autosave.
Device: /dev/sdc [SAT], enabled SMART Automatic Offline Testing.
Device: /dev/sdc [SAT], is SMART capable. Adding to "monitor" list.
Device: /dev/sdc [SAT], state read from /var/lib/smartmontools/smartd.TOSHIBA_HDWE140-708BK08NFBRG.ata.state
Device: /dev/nvme0, opened
Device: /dev/nvme0, Samsung SSD 980 PRO 250GB, S/N:S5GZNG0N921943P, FW:1B2QGXA7, 250 GB
Device: /dev/nvme0, is SMART capable. Adding to "monitor" list.
Device: /dev/nvme0, state read from /var/lib/smartmontools/smartd.Samsung_SSD_980_PRO_250GB-S5GZNG0N921943P.nvme.state
Monitoring 3 ATA/SATA, 0 SCSI/SAS and 1 NVMe devices

Next scheduled self tests (at most 5 of each type per device):
Device: /dev/nvme0, will do test 1 of type S at Fri May 22 12:56:34 2026 +05
Device: /dev/sda [SAT], will do test 1 of type S at Sat May 23 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 1 of type S at Sat May 23 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 1 of type S at Sat May 23 02:26:34 2026 +05
Device: /dev/nvme0, will do test 2 of type S at Sat May 23 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 1 of type L at Sat May 23 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 1 of type L at Sat May 23 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 1 of type L at Sat May 23 03:26:34 2026 +05
Device: /dev/nvme0, will do test 1 of type L at Sat May 23 03:26:34 2026 +05
Device: /dev/sda [SAT], will do test 2 of type S at Sun May 24 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 2 of type S at Sun May 24 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 2 of type S at Sun May 24 02:26:34 2026 +05
Device: /dev/nvme0, will do test 3 of type S at Sun May 24 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 3 of type S at Mon May 25 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 3 of type S at Mon May 25 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 3 of type S at Mon May 25 02:26:34 2026 +05
Device: /dev/nvme0, will do test 4 of type S at Mon May 25 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 4 of type S at Tue May 26 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 4 of type S at Tue May 26 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 4 of type S at Tue May 26 02:26:34 2026 +05
Device: /dev/nvme0, will do test 5 of type S at Tue May 26 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 5 of type S at Wed May 27 02:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 5 of type S at Wed May 27 02:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 5 of type S at Wed May 27 02:26:34 2026 +05
Device: /dev/sda [SAT], will do test 2 of type L at Sat May 30 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 2 of type L at Sat May 30 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 2 of type L at Sat May 30 03:26:34 2026 +05
Device: /dev/nvme0, will do test 2 of type L at Sat May 30 03:26:34 2026 +05
Device: /dev/sda [SAT], will do test 3 of type L at Sat Jun  6 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 3 of type L at Sat Jun  6 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 3 of type L at Sat Jun  6 03:26:34 2026 +05
Device: /dev/nvme0, will do test 3 of type L at Sat Jun  6 03:26:34 2026 +05
Device: /dev/sda [SAT], will do test 4 of type L at Sat Jun 13 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 4 of type L at Sat Jun 13 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 4 of type L at Sat Jun 13 03:26:34 2026 +05
Device: /dev/nvme0, will do test 4 of type L at Sat Jun 13 03:26:34 2026 +05
Device: /dev/sda [SAT], will do test 5 of type L at Sat Jun 20 03:26:34 2026 +05
Device: /dev/sdb [SAT], will do test 5 of type L at Sat Jun 20 03:26:34 2026 +05
Device: /dev/sdc [SAT], will do test 5 of type L at Sat Jun 20 03:26:34 2026 +05
Device: /dev/nvme0, will do test 5 of type L at Sat Jun 20 03:26:34 2026 +05

Totals [Fri May 22 12:26:34 2026 +05 - Thu Aug 20 12:26:34 2026 +05]:
Device: /dev/sda [SAT], will do  13 tests of type L
Device: /dev/sda [SAT], will do  90 tests of type S
Device: /dev/sda [SAT], will do   0 tests of type C
Device: /dev/sda [SAT], will do   0 tests of type O
Device: /dev/sdb [SAT], will do  13 tests of type L
Device: /dev/sdb [SAT], will do  90 tests of type S
Device: /dev/sdb [SAT], will do   0 tests of type C
Device: /dev/sdb [SAT], will do   0 tests of type O
Device: /dev/sdc [SAT], will do  13 tests of type L
Device: /dev/sdc [SAT], will do  90 tests of type S
Device: /dev/sdc [SAT], will do   0 tests of type C
Device: /dev/sdc [SAT], will do   0 tests of type O
Device: /dev/nvme0, will do  13 tests of type L
Device: /dev/nvme0, will do  91 tests of type S
Device: /dev/nvme0, will do   0 tests of type C
Device: /dev/nvme0, will do   0 tests of type O

The output displays:

  • scheduled SMART tests,
  • test types,
  • execution times,
  • planned runs for upcoming months.

Usually the schedule is shown approximately 3 months ahead.

Ensure:

  • Short tests run daily,
  • Long tests follow the expected schedule,
  • execution times are correct,
  • no conflicting rules exist.