From 358211bcfff1e4ce5d512e9278947058405b5d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Zolt=C3=A1n?= Date: Fri, 1 May 2026 22:50:20 +0200 Subject: [PATCH] Wrapper scripts to various mail transfer agents added to .utils collection. --- .metadata | Bin 22487 -> 22712 bytes .utils/mail/README.md | 3 +++ .utils/mail/mail.dummy | 3 +++ .utils/mail/mail.s-nail | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 .utils/mail/README.md create mode 100644 .utils/mail/mail.dummy create mode 100644 .utils/mail/mail.s-nail diff --git a/.metadata b/.metadata index 57bf812c53a8195c954e075de5cba36a28eeaaa4..5ebd60eeef2322cae3f62a329e2f3006b578503e 100644 GIT binary patch delta 259 zcmcbI{Ad1;G{5%%?7rQ ynKTimpx6yE4di$j_~|{ubF>rOAw;qLb$fN==?%%Q5+b g4(sF#jG~)kZGl=o_;F0WU@tj&0~_z==MK}v0US>*nE(I) diff --git a/.utils/mail/README.md b/.utils/mail/README.md new file mode 100644 index 0000000..9b9c331 --- /dev/null +++ b/.utils/mail/README.md @@ -0,0 +1,3 @@ +# Wrapper scripts to various mail transfer agents. +Only needed if your system does not provide the POSIX mailx compatible mail command. If sending email is prohibited from your environment use *mail.dummy* to avoid warnings from cron, etc. +To activate, choose a suitable one then place it somewhere in the path (~/bin or /usr/local/bin are recommended), name it mail and give it execute permission. diff --git a/.utils/mail/mail.dummy b/.utils/mail/mail.dummy new file mode 100644 index 0000000..9985fd4 --- /dev/null +++ b/.utils/mail/mail.dummy @@ -0,0 +1,3 @@ +#!/bin/bash +# +# Dummy file to met the dependencies. Does nothing. diff --git a/.utils/mail/mail.s-nail b/.utils/mail/mail.s-nail new file mode 100644 index 0000000..58c4dd6 --- /dev/null +++ b/.utils/mail/mail.s-nail @@ -0,0 +1,38 @@ +#!/bin/bash +# +# A simple wrapper script to s-nail. Needs a suitable smarthost. +# A copy of sent mail is saved in the /var/mail/$USER mbox file. +# It is recommended to rotate these files e.g via /etc/logrotate.d. +# See also https://manpages.ubuntu.com/manpages/focal/man1/s-nail.1.html + +# SMTP settings - feel free to adjust. +# +# Sender's address is fixed - pay attention to the SPF DNS record! +FROM="no-reply@example.com" +# Default recipient(s), delimited by space. +TO="sysadmin@example.com webadmin@example.com" +SMTP_SERVER="mail.example.com" +# smtp (for tcp/25), smtps (for tcp/465), submission (for tcp/587). +SMTP_PROTO="submission" +# URL escaping required for special characters below. +SMTP_USER="no-reply%40example.com" +SMTP_PASS="topsecret" + +# s-nail call. +# +if [ -x "$(which s-nail 2>/dev/null)" ]; then + # The recipient's address is the last argument. + recipient="${@: -1}" + set -- "${@: 1: $#-1}" + # Our scripts may send mails to the local user. + # In this case, we need replace the recipient address. + [[ "$recipient" = "$USER" ]] && recipient="$TO" + [[ "$recipient" = "$USER@$HOSTNAME" ]] && recipient="$TO" + if [ -n "$recipient" ]; then + "$(which s-nail)" -S from="$FROM" -S v15-compat \ + -S smtp-auth="login" -S smtp-use-starttls \ + -S mta="$SMTP_PROTO://$SMTP_USER:$SMTP_PASS@$SMTP_SERVER" \ + -S record="/var/mail/$USER" \ + "${@}" $recipient + fi +fi