Install and Configure Postfix as a Send-Only SMTP Server

  1. Start with a fully updated and configured Ubuntu server.
  2. Install Postfix
    sudo debconf-set-selections <<< "postfix postfix/mailname string `hostname -f`"
    sudo debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
    
    sudo apt-get install -y mailutils
    
  3. Restart Postfix with sudo service postfix restart
  4. Forward System Emails:
    cp /etc/aliases /tmp/
    cat >> /tmp/aliases << EOF
    root:          user@example.com
    EOF
     
    sudo mv /tmp/aliases /etc/aliases
     
    sudo chown root:root /etc/aliases
     
    sudo newaliases
  5. Test sending an email:
    echo "Test body" | mail -s "Subject Line" root