Automate the installation of postfix on Ubuntu

You can use pre-seeding for this, using the debconf-set-selections command to pre-answer the questions asked by debconf before installing the package.

For example:

debconf-set-selections <<< "postfix postfix/mailname string your.hostname.com"
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
apt-get install --assume-yes postfix

If you want this globally:

dpkg-reconfigure debconf

Then configure it to be "noninteractive"

If you just want it for single install run:

DEBIAN_FRONTEND=noninteractive apt-get install PACKAGE