Following from the previous article, we should have our firewall properly configured to allow the correct ports for our mail server.
Now we can start adding domains and users to our Postfix installation.
As discussed in the initial article where we configured the basic settings for our mail server, Postfix is modular in nature and many of the settings refer to other files on the slice.
Following along with this concept, we will be using a separate file that contains our users as well as one for the domains we will be hosting mail for.
Let's start by making the necessary file references in our Postfix configuration.
Go ahead and open the main.cf file so that we can make our changes:
sudo nano /etc/postfix/main.cf
Now under the MyDestination you should see this:
mydestination = $myhostname, localhost.$mydomain, localhost
This setting tells Postfix what domains it should accept mail for.
As we will be hosting mail for multiple domains we want to reference them all in one file.
To accomplish this, we set the mydestination line as follows:
mydestination = hash:/etc/postfix/mydomains
The same idea applies for our users, so with this file still open look for the alias_maps setting.
Notice this parameter is currently set to the /etc/aliases file as shown below:
alias_maps = hash:/etc/aliases
This line tells Postfix to look in this file for our users when receiving incoming mail. If the recipient is not present, the message will not get delivered as expected.
Editing the /etc/aliases file works great for one domain, but we want this configuration to work for multiple domains.
Therefore, let's add a new line under the alias_maps setting:
virtual_alias_maps = hash:/etc/postfix/virtual
Ok, now let's save the file and move forward with specifying our domains and users.
Before we can restart Postfix to take notice of the changes we have made, we need to actually create the mydomains file that we specified for the mydestination setting above.
sudo nano /etc/postfix/mydomains
Remember this is the file where we state which domains Postfix should accept mail for. Therefore, let's add the following:
localhost OK mail.demoslice.com OK demoslice.com OK
Anytime you make changes to this file the following command must be ran:
sudo /usr/sbin/postmap /etc/postfix/mydomains
Now let's do the same for our virtual file we are going to use to specify our users.
We start by creating the virtual file in the location we referenced in the Postfix configuration.
sudo nano /etc/postfix/virtual
And add your user as shown below:
This tells Postfix to route mail intended for email@example.com to the system user titled 'demo' on the slice.
We also need to run the postmap command on this file when making changes as it recreates the database that Postfix parses:
sudo /usr/sbin/postmap /etc/postfix/virtual
Anytime we make edits to the main Postfix configuration file, we need to restart Postfix to incorporate these changes :
sudo /etc/init.d/postfix restart
Adding domains and multiple users is now a simple process through the use of our mydomains and virtual files.
Now that we have completed all of the necessary steps to setup a fully working mail server on our slice, we can actually start to make use of it for its intended purpose.