Do you want to setup a dedicated mail server for your website, Our mail server depends on three major criteria,

  1. Postfix (SMTP)
  2. Dovecot (IMAP)
  3. Roundcube (Mail Client)

    This article will show how to install and configure the above criteria for setting up a mail server for a domain.


    Postfix is a mail transfer agent (MTA) that delivers electronic mail across globe. It is also called as an SMTP server. Postifx can be integrated with spamfilters, dovecot and  complex SMTP-level access-policies

    To install postfix in a rpm based machines run the below command,

$ yum install postfix

    The default path of the config files are found under this directory /etc/postfix.

    The file is the core of your mail server configuration. The default file lists only a portion of the nearly 300 Postfix parameters. Most Postfix parameters do not need to be changed, but the flexibility is there when it’s required. The path for the file is /etc/postfix/

    The next important config file is the file. The master daemon uses the file for its configuration information. The file contains a line for each Postfix service or transport.
    Each line has columns that specify how each program should run as part of the overall Postfix system. Most of all the file can be edited for additional features such as SMTP authentication,etc.,. Since this is a simple mail server setup, we will not working on this file.

    Whenever you made changes to these files the postfix application should be reloaded or restarted.

$ service postfix reload


$ service postfix restart

Changes to be done on file:

    Since we are going to setup a global access mail server to receive mails from external world hence change the inet_interfaces to all from

inet_interfaces = all

Add the below lines on your files,

alias_maps = hash:/etc/aliases
myhostname =
mynetworks =,
mydestination =
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
local_recipient_maps = $relocated_maps,$alias_maps,proxy:unix:passwd.byname
virtual_alias_maps = hash:/etc/postfix/valias.txt
relay_recipient_maps = hash:/etc/postfix/relay_recipients
relay_domains = hash:/etc/postfix/relay_domains
virtual_mailbox_domains = /etc/postfix/vhosts.txt
virtual_mailbox_base = /var/spool/mail
virtual_mailbox_maps = hash:/etc/postfix/vmaps.txt
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
virtual_mailbox_lock = dotlock
virtual_minimum_uid = 1000
message_size_limit = 20971520
recipient_delimiter = +
smtpd_helo_required = yes
disable_vrfy_command = yes
strict_rfc821_envelopes = yes
invalid_hostname_reject_code = 554
multi_recipient_bounce_reject_code = 554
non_fqdn_reject_code = 554
relay_domains_reject_code = 554
unknown_address_reject_code = 554
unknown_client_reject_code = 554
unknown_hostname_reject_code = 554
unknown_local_recipient_reject_code = 554
unknown_relay_recipient_reject_code = 554
unknown_sender_reject_code = 554
unknown_virtual_alias_reject_code = 554
unknown_virtual_mailbox_reject_code = 554
unverified_recipient_reject_code = 554
unverified_sender_reject_code = 554
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access,
smtpd_recipient_restrictions = reject_invalid_hostname,
check_recipient_access hash:/etc/postfix/recipient_access
smtpd_client_restrictions = check_client_access
smtpd_helo_restrictions = check_helo_access hash:/etc/postfix/helo_access,reject_invalid_hostname

Your myhostname will be your mail server name.

Create the below files that you have mentioned on your files,

$ touch /etc/postfix/valias.txt
$ touch /etc/postfix/relay_recipients
$ touch /etc/postfix/relay_domains
$ touch /etc/postfix/vhosts.txt
$ touch /etc/postfix/vmaps.txt
$ touch /etc/postfix/sender_access
$ touch /etc/postfix/recipient_access
$ touch /etc/postfix/client_access
$ touch /etc/postfix/helo_access

Creating .db files:

    You can create db files once adding a new file using postmap command, the same can be used to update the .db files too. Update their .db files on every changes, The reason for using .db files is postfix is able to lookup information in hashes faster than a normal text file.

$ postmap /etc/postfix/valias.txt
$ postmap /etc/postfix/relay_recipients
$ postmap /etc/postfix/relay_domains
$ postmap /etc/postfix/vhosts.txt
$ postmap /etc/postfix/vmaps.txt
$ postmap /etc/postfix/sender_access
$ postmap /etc/postfix/recipient_access
$ postmap /etc/postfix/client_access
$ postmap /etc/postfix/helo_access

valias.txtYour user emails associated with the username.
relay_recipientsDefines the list of valid email addresses for the domain hosted.
relay_domainsDomains that has been relayed.
vhosts.txtDomains hosted on this mail server.
vmaps.txtContains virtual email address and mailbox location.
sender_accessAllows particular senders to send mails to your mail server.
recipient_accessUsed for access control.
client_accessUsed for access control.
helo_accessUsed for access control.

    On the above files we will editing two of the files for setting up a simple dedicated mail server for a domain valias.txt and vhosts.txt

    We will be creating an email as [email protected] with username jhony. So your valias.txt file will look like as,

$ cat /etc/postfix/valias.txt
[email protected] jhony

    And your vhost.txt file will be like,

$ cat /etc/postfix/vhosts.txt OK

    Update both files hash files by postmap command,

$ postmap /etc/postfix/valias.txt
$ postmap /etc/postfix/vhosts.txt

Create a user:

$ useradd jhony
$ passwd jhony
Changing password for user test.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

    Now we have all set on our postfix configuration, we further work on dovecot configuration on the upcoming article Setting up a Mail server using Roundcube - Part-2 - Centos 7

    Feel free to ask if you have any questions.


  1. Be the first to add a comment.