|
Server : Apache System : Linux s1230 5.15.0-139-generic #149~20.04.1 SMP Tue Jul 14 11:21:49 UTC 2026 x86_64 User : p141464 ( 418825) PHP Version : 7.4.33.12 Disable Function : NONE Directory : /home/www/p141464/sbin/ |
Upload File : |
#!/bin/bash
MESSAGE=$(cat -)
LOGFILE="/tmp/mail.log"
write_logfile() {
echo "$1" >> $LOGFILE
}
write_deadletter() {
echo "$MESSAGE" >> /tmp/deadletter
echo "----------------------------------------------------" >> /tmp/deadletter
}
# read ssmtp.conf
HOST=$(cat /etc/ssmtp.conf)
if [[ ! "$HOST" =~ ^(hostname)\ ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) ]]; then
write_deadletter
write_logfile "$(date +'%d-%m-%Y %T') SMTP server problem Connection refused. mail was saved in file /tmp/deadletter"
exit 1
else
HOST=${BASH_REMATCH[2]}
fi
# check if from in header
[ "$(echo "$MESSAGE" | sed -n '/^$/q;/^from:/Ip')" ] || ARGS="on"
# check if replyto
if [[ "$(echo "$MESSAGE" | sed -n '/^$/q;/^reply-to:/Ip')" ]]; then
REPLYTO=$(echo "$MESSAGE" | grep -E "[rR]eply-[Tt]o:" | cut -d: -f2- | sed 's/ //1')
LOG_REPLYTO="reply-to=$REPLYTO"
fi
OUT=$(echo "$MESSAGE" | msmtp \
--host=${HOST} \
--maildomain=localhost \
--auto-from=${ARGS:-off} \
--read-envelope-from \
--read-recipients \
--set-from-header=auto \
--set-date-header=auto \
--undisclosed-recipients=off \
--logfile=- \
--logfile-time-format="%d-%m-%Y %T" \
$@ 2>/dev/null)
EXITCODE=$?
case $EXITCODE in
65)
[[ $OUT =~ ^([0-9\-]+)\ ([0-9:]+)\ .+\ (from=.+)\ (recipients=.+)\ smtpstatus=.+\ (smtpmsg=.+)\ (errormsg=.+)\ exitcode ]] && write_logfile "${BASH_REMATCH[@]:1} $LOG_REPLYTO"
;;
69)
[[ $OUT =~ ^([0-9\-]+)\ ([0-9:]+)\ .+\ (from=.+)\ (recipients=.+)\ smtpstatus=.+\ (smtpmsg=.+)\ (errormsg=.+)\ exitcode ]] && write_logfile "${BASH_REMATCH[@]:1} $LOG_REPLYTO"
write_deadletter "$MESSAGE"
;;
*)
[[ $OUT =~ ^([0-9\-]+)\ ([0-9:]+)\ .+\ (from=.+)\ (recipients=.+)\ mailsize=.+\ (smtpmsg=.+)\ exitcode ]] && write_logfile "${BASH_REMATCH[@]:1} $LOG_REPLYTO"
;;
esac