Auto-detect sendmail/msmtp for email notifications

Resolve the mailer binary at job creation time and bake the full path
into the service file, so it works regardless of PATH in the systemd
service environment. Warns and skips if neither is found.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthias Johnson 2026-02-14 15:51:31 -07:00
parent 98b180a912
commit c3c534f7ce

5
systab
View file

@ -283,8 +283,11 @@ ExecStopPost=/bin/sh -c 'if [ "\$SERVICE_RESULT" = success ]; then icon=dialog-i
EOF
fi
if [[ -n "$email" ]]; then
local mailer
mailer=$(command -v sendmail || command -v msmtp || true)
[[ -n "$mailer" ]] || { warn "No sendmail or msmtp found, skipping email notification"; return; }
cat >> "$file" <<EOF
ExecStopPost=/bin/sh -c 'if [ "\$SERVICE_RESULT" = success ]; then s=completed; else s="failed (\$EXIT_STATUS)"; fi; printf "Subject: systab: $short_id %s\\n\\n%s at %s\\n" "\$s" "\$s" "\$(date)" | sendmail $email'
ExecStopPost=/bin/sh -c 'if [ "\$SERVICE_RESULT" = success ]; then s=completed; else s="failed (\$EXIT_STATUS)"; fi; printf "Subject: systab: $short_id %s\\n\\n%s at %s\\n" "\$s" "\$s" "\$(date)" | $mailer $email'
EOF
fi
}