Improvements (cronmail) and fixes in mail utilities.

This commit is contained in:
Kovács Zoltán
2026-05-02 23:46:29 +02:00
parent 5b0b5ae2d3
commit 14d499350e
5 changed files with 65 additions and 12 deletions
BIN
View File
Binary file not shown.
+7 -3
View File
@@ -1,3 +1,7 @@
# Wrapper scripts to various mail transfer agents. # Wrapper scripts to various mail 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. Only needed if your system does not provide a local MTA (e.g *sendmail*) and/or a POSIX *mailx* compatible mail command.
To activate, choose a suitable one then place it somewhere in the path (*/usr/local/bin* is recommended), name or symlink it to *mail* and give it execute permission to anyone.
To use them with *crond*, you may need the *cronmail* converter script, which can accept sendmail-formatted mail and convert it into a suitable *mailx* call. You can usually set this script as a mail sender for *crond* using the *CRONDARGS* environment variable.
+52
View File
@@ -0,0 +1,52 @@
#!/bin/bash
#
# This is a sendmail to mailx format converter script.
# It receives a well-formed email text from standard input, parses it,
# and invokes a POSIX mailx compliant mail user agent with the result.
#
# It is primarily designed to use with crond. To activate
# use CRONDARGS="-m pathname_to_cronmail" in/etc/default/cron or
# /etc/sysconfig/crond configuration.
#
# Author: Kovács Zoltán <kovacsz@marcusconsulting.hu>
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
# 2026-05-02 v0.1 Initila release.
# Initialisations.
#
SUBJECT=""
RECIPIENT="$USER" # Default recipient.
MESSAGE=""
MUA="/usr/local/bin/mail" # Custom mail user agent script.
# Parsing the stdin line by line.
#
while IFS= read -r line
do
# Parses the recipient.
if [[ "$line" =~ ^(T|t)o:\ .*$ ]]; then
RECIPIENT="${line#*: }"
# Parses the subject line.
elif [[ "$line" =~ ^(S|s)ubject:\ .*$ ]]; then
SUBJECT="${line#*: }"
# Message body starts with an empty line.
elif [[ "$line" =~ ^$ ]]; then
MESSAGE+="\n"
# Collects the message body lines.
# The first empty line will be stripped.
elif [ -n "$MESSAGE" ]; then
[[ "$MESSAGE" = "\n" ]] \
&& MESSAGE="$line\n" \
|| MESSAGE+="$line\n"
fi
done
# Calls the mail user agent.
#
if [ -x "$MUA" ]; then
if [ -n "$SUBJECT" -o -n "$MESSAGE" ]; then
echo -e "$MESSAGE" | "$MUA" -s "$SUBJECT" "$RECIPIENT"
fi
fi
# That's all, Folks! :)
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
#
# Dummy file to met the dependencies. Does nothing.
+6 -6
View File
@@ -20,7 +20,7 @@ SMTP_PASS="topsecret"
# s-nail call. # s-nail call.
# #
if [ -x "$(which s-nail 2>/dev/null)" ]; then if [ -x "/bin/s-nail" ]; then
# The recipient's address is the last argument. # The recipient's address is the last argument.
recipient="${@: -1}" recipient="${@: -1}"
set -- "${@: 1: $#-1}" set -- "${@: 1: $#-1}"
@@ -29,10 +29,10 @@ if [ -x "$(which s-nail 2>/dev/null)" ]; then
[[ "$recipient" = "$USER" ]] && recipient="$TO" [[ "$recipient" = "$USER" ]] && recipient="$TO"
[[ "$recipient" = "$USER@$HOSTNAME" ]] && recipient="$TO" [[ "$recipient" = "$USER@$HOSTNAME" ]] && recipient="$TO"
if [ -n "$recipient" ]; then if [ -n "$recipient" ]; then
"$(which s-nail)" -S from="$FROM" -S v15-compat \ "/bin/s-nail" -S from="$FROM" -S v15-compat \
-S smtp-auth="login" -S smtp-use-starttls \ -S smtp-auth="login" $([[ "$SMTP_PROTO" = "submission" ]] && echo "-S smtp-use-starttls") \
-S mta="$SMTP_PROTO://$SMTP_USER:$SMTP_PASS@$SMTP_SERVER" \ -S mta="$SMTP_PROTO://$SMTP_USER:$SMTP_PASS@$SMTP_SERVER" \
-S record="/var/mail/$USER" \ -S record="/var/mail/$USER" \
"${@}" $recipient "${@}" $recipient
fi fi
fi fi