#!/bin/bash
set -e

echo "=== sender-mta: starting services ==="

# Fix DNS resolution: ensure Postfix can resolve MX records via BIND9
# Docker's embedded DNS (127.0.0.11) doesn't forward MX queries properly
echo "nameserver 10.0.0.2" > /etc/resolv.conf

# Start rsyslog for mail logging
rsyslogd

# Start OpenDKIM
echo "[*] Starting OpenDKIM (signing mode) ..."
opendkim -x /etc/opendkim.conf
sleep 1

# Start Postfix
echo "[*] Starting Postfix ..."
postfix start

echo "[OK] sender-mta ready  (mail.legit.lab / 10.0.0.10)"

# Keep container alive and tail the log
tail -F /var/log/mail.log 2>/dev/null
