Basic settings in the Postfix main.cf file
After you have installed Postfix, you can work with settings in the main.cf file to further configure Postfix.
Note: This article assumes that you are using a single domain for your email needs.
Modular nature of Postfix
One of the key aspects of Postfix is that it is designed to be a modular package. The base installation itself is fairly small, and the vast majority of the “usual” mail administration, such as anti-spam and anti-virus, is actually conducted by third-party packages like SpamAssassin.
You can begin to see the modular nature of Postfix when you look at the main.cf file. Many settings refer to other files on the server. This setup can seem slightly confusing at first, and your initial reaction might be to hard code the data rather than reference another file with a single word in it. However, we recommend retaining the modularity of Postfix and editing multiple files for what might seem like simple settings. Such modularity will be useful when you start adding multiple domains, users, and aliases to your setup.
The main.cf file
To see the main.cf file, issue the following command:
sudo nano /etc/postfix/main.cf
The file consists of basically three sections. The first section
includes several settings such as the
parameters. The second section has settings for TLS parameters.
This article focuses on the last section, which looks as follows on the democloud server:
myhostname = mail.democloud.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = mail.democloud.com, localhost.democloud.com, localhost relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all
Note: Some of the settings already have the host name from the base Postfix installation.
Although some of the settings might be self-explanatory, the following sections describe them so that you can get a better understanding of Postfix and what you can do with it.
myhostname value was set during the Postfix installation when you
entered the domain name that you want to use. This name also matches the
cloud server host name.
Aliases provide a method for delivering mail to different users without having to set up dozens of different accounts. The default settings in the main.cf reference another file:
alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases
Open that file, as follows:
sudo nano /etc/aliases
The file shows a list of names followed by
root. Mail delivered to the
first name is actually delivered to the second name. You do not need to
set up the
abuse, and other users
for Postfix because mail delivered to those names is sent to
Using the same syntax, you can have all mail for
root delivered to the
admin user by adding the following line (
demo is the main admin user
for the democloud server):
As a result, the delivery destination would change as follows:
- Mail sent to
mailer-daemonis sent to
- Mail to
postmasteris sent to
- Mail sent to
rootis sent to the main admin user
You can adjust the aliases as you see fit, but instead of changing all
root users in the file, it is easier to add the one line as shown.
Adding that line also makes future migration and administration easier.
After you change the aliases file, you must refresh the aliases database for any changes to occur. Use the following command:
Internal emails from packages such as cron jobs do not supply full mail
credentials; they use the
myorigin setting instead. As such, you need
to set this parameter to the main host name of the server.
By default, the setting refers to the /etc/mailname file. To look at the contents, run the following command:
Example output for the democloud server is as follows:
However, you can also set
myorigin by using
$mydomain in the
main.cf file, as follows:
myorigin = $mydomain
Although you haven’t specifically set the
$mydomain variable, Postfix
gets the information from the
myhostname setting, parsing the host
name to gain the main domain name.
myorigin parameter this way allows for easier
administration at a later date because only one setting (
needs to change. All the other parameters take the change from that.
Although you have not yet set the server to receive mail, the
mydestination parameter defines the domains from which the server will
The default looks as follows:
mydestination = mail.democloud.com, localhost.democloud.com, , localhost
The default is adequate when you are setting up mail for a single
domain. However, like with the
myorigin setting, you can reduce future
administration by using the
$mydomain variable as follows:
mydestination = $mydomain, localhost.$mydomain, localhost
For the setup in this series of articles, you do not need this setting. You can leave it blank.
mynetworks parameter defines the network to use. The default value
includes IPv6 settings, which you can remove. The remaining value looks
mynetworks = 127.0.0.0/8
You can use the default values for the remaining settings. They are relevant for more complex configurations.
After the preceding changes, the last section in the example main.cf file looks as follows:
myhostname = mail.democloud.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = $mydomain mydestination = $mydomain, localhost.$mydomain, localhost relayhost = mynetworks = 127.0.0.0/8 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all
Test the settings
As with all packages, after you have made any changes to the configuration, you must restart, as follows:
sudo /etc/init.d/postfix restart
After Postfix is restarted, you can conduct a quick test by sending an email to a working email address, as shown in the following example.
mail email@example.com Subject: test test . Cc:
You should receive an email from the correct user and the correct domain. Check the headers to verify that they are correct.
Configuring Postfix can be a daunting task. This introduction helps with the basics and shows how using variables instead of hard coding domain names can save time and effort in any future administration.
©2018 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License