How to Install and Configure Postfix on Centos 7

Installing Postfix

Postfix comes pre-installed on the CentOS 7 by default, but here's the command to install it as well.

  yum install postfix

Run the below command to check whether postfix is installed or not.

  rpm -qa | grep postfix


 [root@vps]# rpm -qa | grep postfix

After Postfix is installed, you can start the service and enable it to make sure it starts after reboot.

  systemctl start postfix

  systemctl enable postfix

Configuring Postfix

All of the options you need for the service are located in /etc/postfix. The main configuration file for the Postfix service is located at /etc/postfix/ Within the configuration file, there are many options that you can add, some of them more common than others.

 nano /etc/postfix/

Make changes according to the below steps.

Myhostname declares the mail server’s hostname. Hostnames normally have prefixes in them, like this:

  myhostname =

Mydomain declares the domain that is actually handling mail, like this.

  mydomain =

All emails sent from this mail server will look as though it came from this option. You need to set this parameter to the main hostname of the server.

  myorigin = $mydomain

The mydestination parameter defines the domains from which the server will accept mail. It can take values like this.

  mydestination = $myhostname, localhost.$mydomain, $mydomain, mail.$mydomain, www.$mydomain

mail_spool_directory directory where mailbox files are kept.

  mail_spool_directory = /var/spool/mail

Mynetworks declares a list of trusted remote SMTP servers that can relay through the server, like this.

  mynetworks =,

This option specifies the IP protocol version used for server connections.

  inet_protocols = ipv4

save and exit the file.

Start/restart the postfix service.

  systemctl reload postfix

You can check for errors using the following command.

  postfix check

Testing postfix Server

To install mailx using the following command.

  yum install -y mailx

You can send test mail using following command.

  echo "This is message body" | mailx -s "This is Subject" -r ""

You can send test mail With including attachments using following command.

  $ echo "This is message body" | mailx -s "This is Subject" -r "" -a /path/to/attachment

Sender : Receiver:

Finally! You have postfix installed and emails getting sent!