#!/usr/bin/env bash # Configure Uptime Kuma SMTP notification (Mailcow) via Socket.IO API. # Run from machine with network access to Kuma: # export KUMA_URL=http://10.0.10.22:3001 # export KUMA_USER=admin # export KUMA_PASSWORD='your-kuma-password' # export SMTP_USER=alerts@levkine.ca # export SMTP_PASS='mailbox-password' # export SMTP_TO=idobkin@gmail.com # pip install uptime-kuma-api # ./scripts/kuma-setup-smtp.sh set -euo pipefail KUMA_URL="${KUMA_URL:-http://10.0.10.22:3001}" KUMA_USER="${KUMA_USER:-admin}" KUMA_PASSWORD="${KUMA_PASSWORD:-}" SMTP_HOST="${SMTP_HOST:-mail.levkine.ca}" SMTP_PORT="${SMTP_PORT:-587}" SMTP_USER="${SMTP_USER:-alerts@levkine.ca}" SMTP_PASS="${SMTP_PASS:-}" SMTP_TO="${SMTP_TO:-idobkin@gmail.com}" if [[ -z "${KUMA_PASSWORD}" || -z "${SMTP_PASS}" ]]; then echo "Set KUMA_PASSWORD and SMTP_PASS" >&2 exit 1 fi python3 <<'PY' import os import sys try: from uptime_kuma_api import UptimeKumaApi except ImportError: print("pip install uptime-kuma-api", file=sys.stderr) sys.exit(1) url = os.environ["KUMA_URL"] user = os.environ["KUMA_USER"] password = os.environ["KUMA_PASSWORD"] smtp_host = os.environ["SMTP_HOST"] smtp_port = int(os.environ["SMTP_PORT"]) smtp_user = os.environ["SMTP_USER"] smtp_pass = os.environ["SMTP_PASS"] smtp_to = os.environ["SMTP_TO"] with UptimeKumaApi(url) as api: api.login(user, password) # Notification type name in Kuma 1.x is often 'smtp' / 'email' result = api.add_notification( name="Mailcow alerts", type="smtp", isDefault=True, applyExisting=True, smtpHost=smtp_host, smtpPort=smtp_port, smtpSecure=True, smtpIgnoreTLS=False, smtpUsername=smtp_user, smtpPassword=smtp_pass, smtpFrom=smtp_user, smtpTo=smtp_to, ) print(result) PY