Set up a Postfix mail server with Dovecot and RoundCube on CentOS 7
Learn how to set up a email server on a Cloud Server running CentOS 7. This tutorial features Postfix as an SMTP server, Dovecot for POP/IMAP functionality, and RoundCube as a webmail program for users to check and receive email from a web browser.
The tutorial will also walk you through the process of creating and using a self-signed SSL certificate for use in securing incoming and outgoing email connections.
Set up your own professional email server in the blink of an eye. You benefit from large and expandable storage space, your own domain, automatic encryption as well as calendar and office functions or email archiving. IONOS also offers the highest security standards in ISO-certified data centers.
Requirements
- A Cloud Server running CentOS 7.
- Postfix installed and running.
To check the status of Postfix on the server, use the command:
If Postfix is installed and running, you will see the output:
Firewall access
If you have a firewall, you will need to allow access to the following ports:
- SMTP: 25
- POP3: 110
- IMAP: 143
- SMTP Secure: 465
- MSA: 587
- IMAP Secure: 993
- POP3 Secure: 995
Create an SSL certificate
We will create a self-signed SSL certificate to secure incoming and outgoing email connections:
Answer the questions at the prompts, or just hit [Enter] to leave an answer blank. This command will create two files: mailserver.key and mailserver.crt.
Create a folder for the SSL certificate files:
Then move the files into this folder:
- Secures data transfers
- Avoids browser warnings
- Improves your Google ranking
Configure Postfix
The following steps will enable a basic Postfix set-up, allowing you to send and receive mail. For more information on these configurations, consult the official documentation.
Before you begin the configuration changes, be sure that you have the most recent version of Postfix by running the command:
Edit master.cf
First we will edit the /etc/postfix/master.cf file to enable the submission daemon to send and accept mail securely:
Delete the hash mark (#) to un-comment the following lines:
Save and exit the file.
Edit main.cf
The /etc/postfix/main.cf file contains the configuration options for your Postfix installation. Edit this file:
Make the following changes:
Set Hostname
Edit the line which reads:
Delete the hash mark (#) to un-comment the line, and replace host.domain.tld with the hostname of the server:
Set Domain
Edit the line which reads:
Delete the hash mark (#) to un-comment the line, and replace domain.tld with the domain you want to receive mail for:
Enable Other Settings
Delete the hash mark (#) to un-comment the following lines:
Add Configurations
Finally, add the following lines to the end of the file:
Save and exit the file, then restart Postfix to load the new configurations:
Test Postfix with Telnet
To test Postfix we will telnet to the server and perform a basic "handshake protocol," just as an email program would.
First, install Telnet:
Once Telnet is installed, use it to connect to the server's SMTP port:
The server will respond with:
Start by telling the server who the mail is being sent from:
Then tell the server who you are sending mail to, replacing user@example.com with your own username and domain name:
Now add a simple message. Tell the server your message body starts here:
Type the message, then follow it with [Enter], a period ., and [Enter]:
Close the session by typing quit and hitting Enter.
If you are successful, your test message will appear in /home/username/Maildir/new. You can view this message with the command:
To read the message, copy and paste the name of the file (it will be a long name like 1481229255.Vfd01I402b66aM546595.example.com) and read it with more:
You will see the email message, along with all of the header information:
Install and configure Dovecot
We will be using Dovecot as a POP3/IMAP server, so that users can receive and check their email. You can find more information about Dovecot on the Dovecot website.
Install Dovecot with the command:
You can check on the status of Dovecot with the command:
If Dovecot is running, you will see output similar to:
This means that Dovecot is installed and running.
- Professional, automatic email backup tool
- Powerful enterprise-wide search and eDiscovery
- Easy data recovery via one-click restore, download and migrate
Install Roundcube
Roundcube is a free, open source webmail program with robust built-in multilingual capabilities, and many convenient features for your users. You can read more about Roundcube on the Roundcube website.
Roundcube requires several PHP and MariaDB packages as a prerequisite. Install and/or update these first with the command:
Next, create a MariaDB username and database for the Roundcube installation. Log into the MariaDB client with the command:
Log in with the root password, then create a Roundcube database:
Create a user for this database. Note: Be sure to give the user a strong password.
Replace:
- roundcube_user with the username you want to create for your database.
- roundcube_db_password with a strong password for this user.
Then exit MariaDB:
Go to your website's document root. Download the current release from the Roundcube website by using the command:
To find the download URL, visit the current release page on the Roundcube website. Copy the URL for the green "Download" link. You can paste it into the command line by clicking Shift + Insert.
For example, to download the current stable release as of this article's publication the command is:
Uncompress this file using the command:
You can use tab completion to make this process easier. Type sudo tar -xvf roundcube then hit Tab. The shell will automatically fill out the rest of the file name on the command line.
To unzip the file downloaded above, the command is:
Rename the extracted directory roundcube:
Set the ownership of the files to the Apache user:
To complete the installation, switch to a browser and go to the URL http://example.com/roundcube/installer/.
Scroll down to the bottom of the page and click NEXT.
In the next section, you will need to fill out the database information.
Fill out the MariaDB database name, username, and password which you created above. Then scroll down and click CREATE CONFIG.
Note: There are many potential configurations. You can change or set them at any time in the future.
After the config file is created, click CONTINUE to continue.
Click the Initialize database button to set up the database.
Test the mail server configuration by sending a test SMTP email.
- Sender: Your new email address on this server. (For example, jdoe@example.com)
- Recipient: An external email address. (For example, jdoe@gmail.com)
Then click Send test mail. After a few moments, check the external email account to see if your email was sent.
Test the IMAP configurations by logging in with your username and password.
Note that your username is NOT your full email address. For example, log in with the username jdoe, not jdoe@example.com.
Now that the configuration is complete, you can log in at http://example.com/webmail to check and send email.
Reach out in your name every time you hit send — includes domain, 2 GB+ storage, and more.