Postfix is a Mail Transfer Agent (MTA) which is used to route mails between various mail accounts/servers. It is designed to be highly secure and easy to configure. This MTA is also compatible with sendmail. In this article, we will go through the installation and basic configuration of postfix on a CentOS machine, so that you will be able to send and receive mails using this MTA.
On CentOS 5 machines, the default MTA is sendmail. We can install postfix using the yum package manager. Then, we should remove the sendmail MTA, so that postfix will be the default MTA.
yum install postfix
yum remove sendmail
Now, we can go through the basic configuration for setting up a mail server for a single domain. Here, the mail server will provide email accounts via system user accounts. Advanced postfix configuration will include virtual domain hosting to accomplish multiple email accounts on multiple domains.
The main configuration file of postfix is at “/etc/postfix/main.cf”. By default, Postfix does not accept network connections from any host other than the local host. We need to modify the configuration file to enable mail delivery for other hosts on the network.
This is the domain name for the mail server which we are configuring, say domain.com.
mydomain = domain.com
This is the hostname of the server in which we are configuring the postfix MTA.
myhostname = mail.domain.com
This specifies the domain that appears in mail that is posted on this machine. The default is to use the local machine name, $myhostname, which defaults to the name of the machine.
myorigin = $mydomain
This parameter specifies what domains this machine will deliver locally, instead of forwarding to another machine. The default is to receive mail for the machine itself.
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
This parameter specifies what clients to relay mail from. The default is to authorize all clients in the IP subnetworks that the local machine is attached to:
mynetworks = 192.168.0.0/24, 127.0.0.0/8
This specifies what destinations to relay mail to. The default is to authorize all domains (and subdomains) of the domains listed with the mydestination parameter. But, the safest method is to keep it empty so that it will never forward mail from strangers.
This parameter specifies all network interface addresses that the postfix system should listen on; mail addressed to "[email protected][network address]" will be delivered locally, as if it is addressed to a domain listed in $mydestination.
inet_interfaces = all
This sets the path of the mailbox relative to the users home directory and also specifies the style of mailbox to be used. Postfix supports both Maildir and mbox formats and readers are encouraged to read up on the merits of each for themselves. However, in this article we have chosen to use Maildir format (a trailing slash indicates Maildir format.
home_mailbox = Maildir/
Here, the mailbox should be available under ‘/home/user/Maildir’ so that mails to those accounts will be delivered properly. You need to create the mail folder as follows:
chown user:user /home/user/Maildir
chmod -R 700 /home/user/Maildir
Creating the Alias Database
Postfix uses a Sendmail-compatible aliases table to redirect mail for local recipients. Typically, this information is kept in two files: in a text file /etc/aliases and in an indexed file /etc/aliases.db.
# root's mail forwarding
# User aliases
If you edit the aliases file, you must rebuild the aliases database by running the newaliases command.
You need to add postfix service to chkconfig for automatic restart on system reboot.
chkconfig postfix on
You can restart postfix service as follows:
service postfix restart