Install nullmailer (very simple mail transport agent)

# preconfigure nullmailer
debconf-set-selections <<\EOF
nullmailer shared/mailname string $(hostname)
nullmailer nullmailer/relayhost string YOUR_SMTP_HOST smtp --auth-login --user=YOUR_SMTP_USER --pass=YOUR_SMTP_PASS
EOF

# install nullmailer
apt-get install -y nullmailer

# configure mailname
echo "YOUR_DOMAIN" > /etc/mailname

# send test email
echo "This is a test message from ${USER}@${HOSTNAME} at $(date)" | sendmail -f SENDER@YOUR_MAIL.COM RECIPIENT@YOUR_MAIL.COM

# change from / sender address
NULLMAILER_USER=info
# broken? echo "YOUR@EMAIL_ADDRESS.com" > /etc/nullmailer/adminaddr

# ToDo: send mail with subject?
-F Set the full name of the sender for example info@example.com
echo "Subject: Testing" | sendmail ...

# reconfigure
echo "YOUR_DOMAIN.com" > /etc/mailname
echo "smtp YOUR_SMTP_SERVER --auth-login --user=SMTP_USER --pass=SMTP_PASS" > /etc/nullmailer/remotes

#
# override nullmailer to use /etc/aliases
#
echo "root: user1" > /etc/aliases

cat > /usr/local/sbin/sendmail <