Postfix is a mail server software widely used to implement a mail service for many internet domains. It was originally developed as an alternative to the classic sendmail, focusing on the safety, that has historically been the weakest point of sendmail. Since then, it has become very popular thanks to the easy administration and reliability that it provides.
This post is a basic guide to the installation and configuration of a Postfix mail service on a linux Debian server.
1. Installing Postfix
Postfix is available as a module in the standard Debian repository. Therefore, it can be installed just running the apt-get utility:
$ sudo apt-get install postfix
Reading package lists... Done
Building dependency tree
Reading state information... Done
postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin
dovecot-common resolvconf postfix-cdb ufw postfix-doc
The following packages will be REMOVED:
exim4 exim4-base exim4-config exim4-daemon-light
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 4 to remove and 75 not upgraded.
Need to get 1,591 kB of archives.
After this operation, 255 kB disk space will be freed.
Do you want to continue [Y/n]?
As we can see in the output from apt-get, installing postfix implies un-installing other mail server software, such as exim4, that might be previously installed.
Besides, apt-get suggests installing other packages such as postfix-mysql. with postfix-mysql, the configuration of the mail server can be stored in a MySQL database. In case we have the intention to install PostfixAdmin as a web frontend for the management of Postfix, it is advisable to install also postfix-mysql (the full procedure for the installation and setup of PostfixAdmin can be consulted in our post: How to install Postfixadmin to manage a Postfix mail server from a browser).
While Postfix is being installed, an informative screen is displayed with a brief description of the different types of server configuration, followed by a second screen where the desired configuration can be chosen:
Internet site – In the simplest case, the server is connected to internet. It sends email directly to other internet mail servers, and receives email directly from internet.
Internet with smarthost – In this case, the server is also connected to internet, and receives email directly. But it sends email using another server as relay (the smarthost). The smarthost acts as the mailhost for one or more servers.
Satellite system – In a satellite system, al mail is sent and received by a different server.
Local only – This is the case of a server with no internet access, that doesn’t send or receive email from other servers.
We choose “Internet Site” for our sample installation. Installation continues, and a new screen is displayed requesting the name of the mail domain for the server. If email with addresses of the form email@example.com is to be sent from this server, “mydomain.com” needs to be specified here
This completes the installation, and the details of the default configuration chosen for the server are written to screen:
Unpacking postfix (from .../postfix_2.9.6-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up postfix (2.9.6-2) ...
Adding group `postfix' (GID 124) ...
Adding system user `postfix' (UID 116) ...
Adding new user `postfix' (UID 116) with group `postfix' ...
Not creating home directory `/var/spool/postfix'.
Adding tcp map entry to /etc/postfix/dynamicmaps.cf
Adding sqlite map entry to /etc/postfix/dynamicmaps.cf
Adding group `postdrop' (GID 125) ...
setting myhostname: wheezy.openalfa.com
setting alias maps
setting alias database
changing /etc/mailname to openalfa.com
setting destinations: openalfa.com, wheezy.openalfa.com, localhost
setting mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: all
Postfix is now set up with a default configuration. If you need to make
/etc/postfix/main.cf (and others) as needed. To view Postfix configuration
values, see postconf(1).
After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
[ ok ] Stopping Postfix Mail Transport Agent: postfix.
[ ok ] Starting Postfix Mail Transport Agent: postfix.
(Reading database ... 205932 files and directories currently installed.)
Removing exim4-base ...
Processing triggers for man-db ...
As we can see, the installation creates a ‘postfix’ user, and ‘postfix’ and ‘postdrop’ groups. The mail service will run with the privileges of the ‘postfix’ user.
All the configuration files are located under /etc/postfix. The main configuration file is main.cf. In that file, we can review and modify the default configuration.
With this, we can already send email through postfix. For instance, we can test the installation sending a test email, using mailx of other mail client available in the system:
$ mailx firstname.lastname@example.org
Subject: Test Postfix installation
This is a test, please discard
And check that the email arrives in the inbox of “email@example.com”, with “firstname.lastname@example.org” as sender (where “user” is the unix user we were connected as when sending the email).
Note: Depending on the Subject and content of the email sent, it might happen that the message is received in the “Spam” folder.