This article outlines basic steps for setting up a mail server using popular components such as Postfix and Dovecot. Mail server setup may vary depending on the selected software and operating system, as well as the environment’s specific settings. This guide focuses on Ubuntu and Debian operating systems.
WarningSMTP ports 25, 465, and 587 are blocked by default on Gcore Cloud VMs to prevent spam abuse. Before setting up a mail server, contact the Gcore support team to request port unblocking with a business justification. The use of email services must comply with Gcore terms of use; accounts violating these terms will be blocked. For managed email hosting without these restrictions, consider Gcore Hosting.
Steps
- Create a Virtual Machine.
Install a Cloud VM using the VM creation guide. The minimum available configuration (1vCPU and 2 GB RAM) is sufficient to install and run a mail server.
- Check internet access.
Check the Network settings tab in the machine settings. The interface must be set to the public to access the internet.
If the private network method was initially selected, a floating IP address is required to access the internet.
InfoEnsure SMTP ports are unblocked before proceeding with mail server installation. See the warning at the top of this guide for details.
-
Connect to the Gcore Cloud VM via SSH or the VNC console in the Customer Portal.
-
Install Postfix.
Postfix is one of the popular Mail Transfer Agents (MTAs) responsible for sending and delivering mail messages. To install Postfix, run the following commands:
sudo apt-get update
sudo apt-get install postfix
During Postfix installation, a prompt appears to select a configuration type. Select the Internet Site option, enter the fully qualified hostname of the server, and click <Ok>.
- Configure Postfix.
Navigate to the Postfix configuration file:
sudo nano /etc/postfix/main.cf
In this configuration file, edit the following parameters:
myhostname = your_server_domain.com
mydestination = your_server_domain.com, localhost.localdomain, localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
-
myhostname : Specify the fully qualified domain name of the Virtual Server on which Postfix is running.
-
mydestination : Specify the domains for which mail will be delivered locally instead of being forwarded to another host.
-
mynetworks : Specify a list of networks or IP addresses from which mail messages are allowed to be sent through this server.
Save the changes and restart Postfix:
sudo service postfix restart
More information about Postfix is available in the Postfix documentation.
- Install Dovecot.
Dovecot is an IMAP (Internet Message Access Protocol) and POP3 (Post Office Protocol 3) server that provides access to mailboxes. To install Dovecot, run the following command:
sudo apt-get install dovecot-imapd dovecot-pop3d
- Configure Dovecot.
Add the following SSL parameters:
listen = *, ::
ssl = required
ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key
Insert the required SSL parameters below, as noted in the screenshot, after listen = *, ::.
Save the changes and restart Dovecot:
sudo service dovecot restart
- Create mailboxes.
After configuring Postfix and Dovecot, create mailboxes for users. For each user, run the following commands:
sudo useradd -m -s /usr/sbin/nologin username
sudo passwd username
Create a password for each user and retype it. The password will be saved automatically.
- Add DNS records.
Configure DNS settings for the mail server. Refer to the DNS setup guide for step-by-step instructions.
- Test and verify.
Restart Postfix and Dovecot to apply the changes.
sudo service postfix restart
sudo service dovecot restart
Use an email client (for example, Thunderbird) to send a test email from one of the created email addresses. After sending a test email, verify receipt in the email client or webmail. The Postfix and Dovecot logs are located in the following directory: