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 <<EOF
#!/bin/bash
 
export NULLMAILER_USER=\$(cat /etc/aliases | grep $(id -un) | cut -d":" -f2 | tr -d '[[:space:]]')
/usr/sbin/sendmail \$@
EOF
chmod a+x /usr/local/sbin/sendmail
 
 
# parameter
NULLMAILER_USER=user1
NULLMAILER_NAME="My User"
NULLMAILER_HOST=www.example.com
 
# send mail with attachment
# install uuencode (included in sharutils)
apt-get install -y sharutils
uuencode /PATH_TO_FILE FILE_TITLE | sendmail -f SENDER@YOUR_MAIL.COM RECIPIENT@YOUR_MAIL.COM