#!/usr/bin/bash -ue # The script assumes that: # - SMTP_PORT and SMTP_USER are environment variables to store the port and account to use on the SMTP server. # - if authentication is to be used, credentials called smtppass and smtpuser is passed by sd. status="${1}" service_name="${2}" ## identification to use fot the mail server: # identifyme is set to 1 if authentication is possible, 0 otherwise identifyme=1 smtp_pass=$(systemd-creds cat smtppass) || identifyme=0 smtp_user=$SMTP_USER smtp_port=$SMTP_PORT smtp_server="redisdead.crans.org" smtp_rcpt="nounous@crans.org" email="sdcron@crans.org" ## Write the email in a temporary file tmp=$(mktemp /tmp/mail.XXXXX) echo "From: sdcron To: nounous@crans.org Subject: ${status} of the service ${service_name}. Date: $(date -R) Salut, tout est dans le sujet $\ddot\smile$! -- Cordialement sdcron " | tee "$tmp" ## Send the email case identifyme in 0 ) curl --ssl-reqd \ --url "smtps://${smtp_server}:${smtp_port}" \ --mail-from "${email}" \ --mail-rcpt "${smtp_rcpt}" \ --upload-file "$tmp" ;; 1 ) curl --ssl-reqd \ --url "smtps://${smtp_server}:${smtp_port}" \ --user "${smtp_user}:${smtp_pass}" \ --mail-from "${email}" \ --mail-rcpt "${smtp_rcpt}" \ --upload-file "$tmp" ;; esac rm "$tmp"