Beruflich Dokumente
Kultur Dokumente
Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for £10.00 /
month.
HostPresto! > Community > Tutorials > How to Setup an Email Server on CentOS 7
Liptan Biswas
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
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 1/28
10/22/2019 How to Setup an Email Server on CentOS 7
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 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
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 2/28
10/22/2019 How to Setup an Email Server on CentOS 7
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.
Now run the following command to create certi cate and key les.
openssl req -x509 -nodes -newkey rsa:2048 -keyout server.key -out server.cr
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.
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 4/28
10/22/2019 How to Setup an Email Server on CentOS 7
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
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 5/28
10/22/2019 How to Setup an Email Server on CentOS 7
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
home_mailbox = mail/
mynetworks = 127.0.0.0/8
inet_interfaces = all
inet_protocols = all
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
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,
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
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 6/28
10/22/2019 How to Setup an Email Server on CentOS 7
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/ 7/28
10/22/2019 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
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 8/28
10/22/2019 How to Setup an Email Server on CentOS 7
nano /etc/dovecot/conf.d/10-mail.conf
#
#
#mail_location =
mail_location = maildir:~/mail
nano /etc/dovecot/conf.d/20-pop3.conf
#pop3_uidl_format = %08Xu%08Xv
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 9/28
10/22/2019 How to Setup an Email Server on CentOS 7
# 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.
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 10/28
10/22/2019 How to Setup an Email Server on CentOS 7
If you do not have telnet installed, then you can run the following command to install telnet.
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:
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 11/28
10/22/2019 How to Setup an Email Server on CentOS 7
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.
quit
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 12/28
10/22/2019 How to Setup an Email Server on CentOS 7
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
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 13/28
10/22/2019 How to Setup an Email Server on CentOS 7
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. LanguagesD. Set pre-defined settings for specific IMAP serversC Turn
S Save data
Q Quit
Command >>
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 14/28
10/22/2019 How to Setup an Email Server on CentOS 7
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 ex
[localhost]: yourdomain.com
Server SettingsGeneral
-------
1. Domain : rackvoucher.com
2. Invert Time : false
3. Sendmail or SMTP : SendmailA. Update IMAP Settings : localhost
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 15/28
10/22/2019 How to Setup an Email Server on CentOS 7
3. Se d a o S : Se d a p
. Update Sett ggs : oca ost
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
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
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
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 16/28
10/22/2019 How to Setup an Email Server on CentOS 7
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
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.
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 17/28
10/22/2019 How to Setup an Email Server on CentOS 7
Liptan Biswas
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/ 18/28
10/22/2019 How to Setup an Email Server on CentOS 7
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 19/28
10/22/2019 How to Setup an Email Server on CentOS 7
Comments
29 Comments hostpresto.com
1 Login
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
⛺
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 20/28
10/22/2019 How to Setup an Email Server on CentOS 7
2△ ▽ • Reply • Share ›
Starting httpd: [Wed Jan 23 16:47:36 2019] [warn] The Alias directive in /etc/httpd/conf/httpd.conf
at line 1014 will probably never match because it overlaps an earlier Alias.
Syntax error on line 1017 of /etc/httpd/conf/httpd.conf:
AllowOverride not allowed here
[FAILED]
Is there anything wrong / missing in the Alias statement given above, by any chance?
I noticed a line break was needed for "Options Indexes FollowSymLinks"
[SOLVED] The <directory> lines were missing. The Alias should be stated as follows
(without the space between '<' and 'Directory'):
Alias /webmail /usr/share/squirrelmail
< Directory /usr/share/squirrelmail>
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 21/28
10/22/2019 How to Setup an Email Server on CentOS 7
y / / / q
Options Indexes FollowSymLinks
RewriteEngine On
AllowOverride All
DirectoryIndex index.php
Order allow,deny
Allow from all
< /Directory>
Now I'm not sure why I still get this warning but it doesn't seem to disturb the webmail:
[warn] The Alias directive in /etc/httpd/conf/httpd.conf at line 1014 will probably never match
because it overlaps an earlier Alias.
△ ▽ • Reply • Share ›
I am having some issues with httpd/Apache won't start. I have CentOS 7 the latest build with the
Everything package with Server option installed, fresh install, but couldn't get it going. Errors out
with Failed to start the Apache Httpd. Wondering is anyone can pointing me to the right direction.
Manual install of Apache won't start either. Thanks.
Update:
reinstall Apache http server worked. Thanks
△ ▽ • Reply • Share ›
What if you have already installed vpssim on the cent Os, how do you configure hostpresto on it?
△ ▽ • Reply • Share ›
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
Cheers!
△ ▽ • Reply • Share ›
△ ▽ • Reply • Share ›
Great, clear guide but I'm stuck at the testing stage after the Dovecot installation. :-(
[SOLVED] My bad... that's because I left a few blank spaces between the line start and
"submission". Didn't know those config files cared about spaces at the beginning.
△ ▽ 1 • Reply • Share ›
ALSO ON HOSTPRESTO.COM
My HostPresto
Help
Community
Contact
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 26/28
10/22/2019 How to Setup an Email Server on CentOS 7
COMPANY
About
Articles
Blog
Terms
Privacy Policy
Sitemap
SERVICES
Web Hosting
Wordpress Hosting
Magento Hosting
Reseller Hosting
Domain Names
Cloud Servers
Email Hosting
Hosted Apps
SSL Certi cates
cPanel Hosting
Website Builder
Free Charity Hosting
Free Open Source Project Hosting
FileMaker Hosting
Plesk Hosting
Windows Hosting
ASP Hosting
Node.js Hosting
Serif WebPlus Hosting
THINGS OF INTEREST
23rd Aug 2019
New Website, New Packages and New Prices Coming Soon
https://hostpresto.com/community/tutorials/how-to-setup-an-email-server-on-centos7/ 28/28