#!/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" <