Files
Ketan Patel 7ead00647b
Build and Push Docker Image / build (push) Successful in 1m25s
Publish Alpine musl distroless Postfix as the sole latest image
2026-10-03 00:17:09 -04:00

39 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Host-side helper; the container only executes Postfix's native sendmail.
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 [container] recipient [sender] [subject]" >&2
exit 1
fi
if [[ $1 == *@* ]]; then
container=${CONTAINER:-postfix-relay}
else
container=$1
shift
fi
recipient=${1:?Recipient required}
from=${2:-}
subject=${3:-Test Email from Postfix Relay}
if [[ ! $recipient =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+$ ]]; then
echo "Invalid recipient" >&2
exit 1
fi
if [[ -z $from ]]; then
domain=$(docker exec "$container" postconf -h mydomain)
from="noreply@$domain"
fi
if [[ ! $from =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+$ || $subject == *$'\r'* || $subject == *$'\n'* ]]; then
echo "Invalid sender or subject" >&2
exit 1
fi
docker exec -i "$container" sendmail -i -f "$from" "$recipient" <<MAIL
From: $from
To: $recipient
Subject: $subject
Test email from the Postfix relay, submitted at $(date -u).
MAIL
echo "Message submitted; inspect delivery status with docker logs $container."
docker exec "$container" postqueue -p