Professional Documents
Culture Documents
Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for 10.00 / month.
View Plans
HostPresto! > Community > Tutorials > How to Setup an Email Server on CentOS 7
Liptan Biswas
0 3 0
In this tutorial we are going to learn how to set up an Email server using Post x, Dovecot and Squirrelmail on CentOS 7.x. We will be using Post x
for SMTP (Simple Mail Transfer Protocol), Dovecot for POP/IMAP and Squirrelmail as webmail client to send or receive emails. We will also learn to
setup MX records which is important to route the emails.
Requirements
The requirements for setting up email server will simply be a VPS or dedicated server with a fresh CentOS 7.x install and also a static IP address. In
this tutorial we will be using a root account to execute the commands. If you are logged in as non-root user, use sudo command at the start of
all the commands or you can execute su command to login as root user.
Setting up DNS
It is very important to setup DNS records, speci cally MX records in your domain control panel. Login to your domain control panel and change
your DNS settings to add these following MX records entries. A typical MX record will look like this.
Where MX is the type of record, MX stands for Mail Exchangers. Next is the value for host, you can either enter your domain name or you can also
use @ which represents the value of the zone name which is same as your domain name. Next you will have to choose the destination, you will
need to enter the hostname or FQDN of your mail server.
The next value is the priority. The lowest number is priority. For example 0 will have the highest priority and 20 will have a lower priority. Priority is
used because we can add multiple MX records for a single domain, mail is forwarded to the server having highest priority. If the server having
highest priority is not available then mail will be forwarded to the server having second highest priority. Next is TTL or Time to Live, it should be set
to 3600.
It is very important that you also setup an A record for your hostname of the mail server FQDN. Again select the type as A record, host should be
the hostname you are using in your FQDN, for example in this case we have used the hostname as mail.yourdomain.com, hence our host will
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 1/14
11/17/2017 How to Setup an Email Server on CentOS 7
be mail. Next, at destination, enter the IP address of your server. A records does not have priority option hence, you will only need to provide
TTL.
Once you have con gured your DNS settings, you will need to wait some time so that DNS gets propagated. It usually takes around two hours
these days. Once propagated, you can check your MX records here.
Until your DNS gets propagated, you can continue with the installation.
Installing Post x
Login to your server and run the following command to update the repository and packages available in your system.
yum -y update
Now update the hostname of your system to the FQDN you want to use with your mail server. Run the following command to change your
hostname.
hostname mail.yourdomain.com
You can replace the hostname according to your choice, but it should be same as the FQDN which we have used in our DNS settings.
Now add the hostname entry in the host les of your system. Edit /etc/hosts les using your favorite editor. For example if your are using nano
then you will need to run the following command.
nano /etc/hosts
You will see two lines of entries in there, append your server IP address followed by hostname at the end of the le. It should look like the one
shown below.
Before con guring post x we will need to con gure SSL which will be used to encrypt and secure the emails.
mkdir /etc/postfix/ssl
cd /etc/postfix/ssl
Now we will have to create SSL certi cates. If you do not have openssl installed you can install it using the following command.
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 2/14
11/17/2017 How to Setup an Email Server on CentOS 7
Now run the following command to create certi cate and key les.
openssl req -x509 -nodes -newkey rsa:2048 -keyout server.key -out server.crt -nodes -days 365
Now you will be asked some information which is to be added into your CSR (Code Signing Request). You will be asked your country name in two
letters, for example consider IN for India. Then you will be asked about the state or province. Then you will be asked about your city and
organization. Finally, a common name of your server and your email address. If you want to leave some details blank use full stop or period ( . )
sign. You can also enter the default values just by pressing enter. Example output is given below.
This will generate the key le and certi cates and will save then in /etc/postfix/ssl directory.
Now edit post x con guration le which can be found at /etc/postfix/main.cf, with your favorite editor.
nano /etc/postfix/main.cf
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
home_mailbox = mail/
mynetworks = 127.0.0.0/8
inet_interfaces = all
inet_protocols = all
inet_interfaces = localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 3/14
11/17/2017 How to Setup an Email Server on CentOS 7
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_key_file = /etc/postfix/ssl/server.key
smtpd_tls_cert_file = /etc/postfix/ssl/server.crt
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
Now open another con guration le /etc/postfix/master.cf using your favorite editor.
nano /etc/postfix/master.cf
Installing Dovecot
Now install Dovecot using the following command:
Once Dovecot is installed, edit the following le using your favorite editor.
nano /etc/dovecot/conf.d/10-master.conf
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 4/14
11/17/2017 How to Setup an Email Server on CentOS 7
# Postfix smtp-auth
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
nano /etc/dovecot/conf.d/10-auth.conf
Append login at the end of the line auth_mechanisms = plain to make it look like
nano /etc/dovecot/conf.d/10-mail.conf
#
#
#mail_location =
mail_location = maildir:~/mail
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 5/14
11/17/2017 How to Setup an Email Server on CentOS 7
nano /etc/dovecot/conf.d/20-pop3.conf
#pop3_uidl_format = %08Xu%08Xv
# Note that Outlook 2003 seems to have problems with %v.%u format which was
# Dovecot's default, so if you're building a new server it would be a good
# idea to change this. %08Xu%08Xv should be pretty fail-safe.
#
pop3_uidl_format = %08Xu%08Xv
Now if you have a rewall running you will need to allow port number 25, 587, 465, 110, 143, 993, 995 and 80. All the ports except 80 are used to
send and receive emails and port 80 is used to make HTTP connections. HTTP connections will be used to access Squirrelmail using web interface.
To unblock all these ports from rewall, run the following commands.
If you do not have telnet installed, then you can run the following command to install telnet.
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 6/14
11/17/2017 How to Setup an Email Server on CentOS 7
Once you are connected using telnet you will see following output.
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 mail.rackvoucher.com ESMTP Postfix
Now you can also send email using telnet. Use the following command to enter the sender username.
mail from:
To enter the email of recipient, you can use the use the following command.
rcpt to:
data
Once you have entered your message, enter dot (.) to nish the message. Finally enter quit to exit telnet.
Trying 104.36.18.239...
Connected to mail.rackvoucher.com.
Escape character is '^]'.
+OK Dovecot ready.
It tells that Dovecot is working ne, you can login to your mail account by providing login command, then use pass command to enter your
password. To view the mails in your account, use retr command.
user mailuser
+OK
pass Password
+OK Logged in.
retr
-ERR There's no message 1.
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 7/14
11/17/2017 How to Setup an Email Server on CentOS 7
quit
+OK Logging out.
Connection closed by foreign host.
Installing Squirrelmail
As we have both Post x and Dovecot working, we can now install Squirrelmail to your server. Squirrelmail does not comes with the default
CentOS repository, hence you will need to add EPEL repository into your system using the following command.
After installing Squirrelmail you can con gure it by running the con guration script.
cd /usr/share/squirrelmail/config/
./conf.pl
In Option 1 you can change your organisation preferences. It is recommended to change it according to your organisation in production
environment. If you choose option 1, you will see following output.
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 8/14
11/17/2017 How to Setup an Email Server on CentOS 7
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://squirrelmail.org/
8. Provider name : SquirrelMailR Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >>
Change the organisation name, logo and title according to your need. Once done, return to main menu using R command. In main menu choose
option 2 for Server settings.
The domain name is the suffix at the end of all email addresses. If for example, your email address is
[localhost]: yourdomain.com
Server SettingsGeneral
-------
1. Domain : rackvoucher.com
2. Invert Time : false
3. Sendmail or SMTP : SendmailA. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmailR Return to Main Menu
C Turn color off
S Save data
Q QuitCommand >> 3You now need to choose the method that you will use for sending
messages in SquirrelMail. You can either connect to an SMTP server
or use sendmail directly.
1. Sendmail 2. SMTP Your choice [1/2] [1]: 2
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 9/14
11/17/2017 How to Setup an Email Server on CentOS 7
Now save your setting by giving S command and nally quit using Q command.
Now you will need to install the Apache web server, so that we can access Squirrelmail using web interface. Run the following command to install
Apache web server.
Once Apache is installed, edit the con guration le to add a new virtual host.
nano /etc/httpd/conf/httpd.conf
Save the le and start and enable Apache web server using the following commands.
Now create email users, run the following command to add a user.
Theabove command will add a new user liptan and the attribute -s /sbin/nologin will deny login using SSH. Last command will create a
password for the new user.
Now you can browse Squirrelmail by going to following link into the browser.
http:///webmail
Once you login you will see the following webmail interface.
You can now read your emails and send emails through this interface.
Conclusion
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 10/14
11/17/2017 How to Setup an Email Server on CentOS 7
In this tutorial we have installed an email server, using Post x, Dovecot and the Squirrelmail webmail client. You can now successfully deploy the
email server and start sending via the mail server.
Liptan Biswas
0 3 0
Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for 10.00 / month.
View Plans
Related Posts
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 11/14
11/17/2017 How to Setup an Email Server on CentOS 7
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 12/14
11/17/2017 How to Setup an Email Server on CentOS 7
Comments
12 Comments hostpresto.com
1 Login
Sort by Best
Recommend Share
Name
Aug 07 17:39:08 mail.xyz.org postfix/postfix-script[10396]: fatal: unable to create missing queue directories
Aug 07 17:39:08 mail.xyz.org postfix/postfix-script[10397]: fatal: Postfix integrity check failed!
Aug 07 17:39:08 mail.xyz.org systemd[1]: postfix.service: control process exited, code=exited status=1
Aug 07 17:39:08 mail.xyz.org systemd[1]: Failed to start Postfix Mail Transport Agent.
Now to solve this issues, please note a small error but the writer in
sudo vi /etc/postfix/main.cf
inet_interfaces = all
inet_protocols = all
inet_interfaces = localhost
inet_interfaces = all is overwritten by localhost binding it to localhost. Delete or uncomment that line, then restart postfix.
Cheers!
Reply Share
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 13/14
11/17/2017 How to Setup an Email Server on CentOS 7
Reply Share
ALSO ON HOSTPRESTO.COM
How to Install and Setup Mantis Bug Tracker on Ubuntu 16.04 5 Free Tools for Testing Website Speed
1 comment 5 months ago 1 comment 2 months ago
Douglas C. R. Paes Hello.Thank you for the blogpost.One minor Load Focus https://loadfocus.com/websi... Website Speed Test Tool to
mistake, the php library package is libapache2-mod-php7.0, and not analyse website speed results and find speed bottlenecks.
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 14/14