Set up a Postfix mail server with Dovecot and Squirrelmail on Ubuntu 16.04
Learn how to set up a email server on a Cloud Server running Ubuntu 16.04. This tutorial features Postfix as an SMTP server, Dovecot for POP/IMAP functionality, and Squirrelmail 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.
- Professional, automatic email backup tool
- Powerful enterprise-wide search and eDiscovery
- Easy data recovery via one-click restore, download and migrate
Requirements
- A Cloud Server running Ubuntu 16.04.
- A valid domain name pointing to the server.
Firewall access
You will need to set your firewall(s) to allow access to the following ports:
- SMTP: 25
- POP3: 110
- IMAP: 143
- SMTP Secure: 465
- MSA: 587
- IMAP Secure: 993
- POP3 Secure: 995
By default, the Cloud Panel Firewall denies access to all but the most commonly-used ports.
Install Postfix
To install Postfix, first update your packages:
Then install Postfix:
Postfix is installed by default on most Ubuntu 16.04 systems, so this command will most likely exit with a message that postfix is already the newest version (3.1.0-3)..
If Postfix continues with an installation, simply accept all of the defaults at each prompt to complete the process.
Configure Postfix
After the installation is complete, run the command to configure Postfix:
Enter the following values at the prompts, replacing example.com with your own domain name. Use the up arrow and down arrow to move up and down to highlight answers, and Enter to select your answer.
- Select OK to proceed.
- Choose Internet Site.
- System Mail Name: example.com
- Root and postmaster mail recipient: root
- Other destinations for mail: example.com, localhost.example.com, localhost
- Force synchronous updates on mail queue?: No
- Local networks: 127.0.0.0/8
- Use procmail for local delivery?: No
- Mailbox size limit (bytes): 0
- Local address extension character: +
- Internet protocols to use: all
After the initial Postfix configuration has been done, you can change Postfix settings with the command:
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.
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
Set up SMTP AUTH
SMTP AUTH is a basic method of securing your mail server. We strongly recommend the use of SMTP AUTH on all mail servers.
To begin, use the following commands to configure Postfix to use SMTP AUTH:
Replace example.com with your own domain name:
Next, create the file /etc/postfix/sasl/smtpd.conf and open it for editing:
Add the following content:
After you have finished configuring Postfix, restart the Postfix daemon with the command:
Install SASL
Postfix will use SASL to handle the authentication with SMTP AUTH. Now that Postfix has been configured to use SMTP AUTH, install SASL with the command:
After the installation is done, edit /etc/default/saslauthd:
Scroll down to the line:
Change START to yes:
Below that line, add the following three lines:
Scroll down to the bottom of the file to the line:
Change the last line to read:
Save and exit the file.
Next, run the following command to update the dpkg state:
Note: If you get an error message that /var/spool/postfix/var/run/saslauthd does not exist, ignore it. This directory will be created when you start the SASL daemon.
Create a symlink for the config file:
And finally, start the SASL daemon:
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:
This indicates that Postfix is up and running.
Next, greet the server:
The server will respond with:
The following lines indicate that SMTP AUTH is working:
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 /root/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 1482257384.Vfc00I60512M258205.localhost.localdomain) and read it with more:
You will see the email message, along with all of the header information:
- The world’s leading email and calendar solution
- Secure hosting from a single source
- Anytime remote access with Microsoft Outlook
Install and configure Dovecot
Dovecot is the default POP3/IMAP server for Ubuntu, and is installed on most Ubuntu 16.04 servers by default. Update Dovecot and install the imapd package with the command:
You can check on the status of Dovecot with the command:
If Dovecot is running, you will see output similar to:
Note the line that reads:
This means that Dovecot is installed and running.
Set the permissions on the /var/mail directory so that Dovecot can create folders for new users:
Install and configure Squirrelmail
Install Squirrelmail with the command:
You will need to edit your Apache configurations to add an alias for Squirrelmail. This directive will need to be inserted inside the VirtualHost command block in the site's main Apache configuration file.
By common convention, this Apache configuration file is usually /etc/apache2/sites-available/example.com.conf on Ubuntu.
Note: The location and filename of a site's Apache configuration file can vary.
Edit this file with your editor of choice, for example with the command:
Scroll through the file until you find the VirtualHost command block, which will look like:
Add the following to VirtualHost command block:
Be sure to put these lines outside any Directory command blocks. For example:
Save and exit the file, then restart Apache for the changes to take effect:
After Apache restarts, you can test Squirrelmail by visiting the URL http://example.com/squirrelmail in a browser.
Reach out in your name every time you hit send — includes domain, 2 GB+ storage, and more.