CLOUD
Guides

Email Server Setup: Complete Technical Guide

CLOUD|November 21, 2025|3 min read|534 views
Email Server Setup: Complete Technical Guide

Postfix + Dovecot + SPF + DKIM + DMARC + SSL = complete email server. We explain setup on Ubuntu — step by step.

Introduction: Why Run Your Own Mail Server?

Setting up a dedicated email server gives you complete control over corporate email: from account creation to security policies to storage management. Instead of relying on external services, your data stays on your server under your full administration.

This guide covers setting up a complete mail server on a VPS using industry-standard components. We will use Postfix for sending, Dovecot for receiving, with full SSL security and authentication records.

Prerequisites

RequirementMinimumRecommended
CPU1 vCPU2 vCPU
Memory2 GB RAM4 GB RAM
Storage20 GB SSD40 GB SSD or more
OSUbuntu 22.04+Ubuntu 24.04 LTS
Static IPRequiredWith correct PTR record

Step 1: Prepare the Server

Before installing any mail software, prepare the server with the essentials:

  1. Update the system completely
  2. Set the hostname to match your domain (e.g., mail.yourdomain.com)
  3. Verify port 25 is open (some VPS providers block it by default)
  4. Install a firewall and open required ports: 25, 465, 587, 993, 995

Step 2: Configure DNS Records

Before installing software, configure DNS records since propagation takes time:

RecordTypeValue
mail.yourdomain.comAServer IP address
yourdomain.comMXmail.yourdomain.com (priority 10)
yourdomain.comTXT (SPF)v=spf1 ip4:YOUR_IP -all
PTR recordPTRmail.yourdomain.com (set by hosting provider)

Step 3: Install Postfix

Postfix is the SMTP server responsible for sending and receiving messages. It is known for being secure, lightweight, and reliable. During installation, select "Internet Site" and use your full domain.

Essential settings in main.cf:

  • myhostname: mail.yourdomain.com
  • mydomain: yourdomain.com
  • myorigin: $mydomain
  • inet_interfaces: all
  • smtpd_tls_cert_file: SSL certificate path
  • smtpd_tls_key_file: Private key path

Step 4: Install Dovecot

Dovecot handles IMAP and POP3 protocols that allow email clients to read messages. Install Dovecot with IMAP support (the most common protocol since it keeps messages on the server).

Important settings:

  • Enable SSL and specify certificate paths
  • Set the storage format to Maildir
  • Enable SASL authentication for Postfix integration

Step 5: Install SSL Certificate

An SSL certificate is essential for encrypting communication between email clients and the server. Use Let's Encrypt for a free certificate. Ensure the certificate covers mail.yourdomain.com.

Step 6: Configure DKIM

Install OpenDKIM to digitally sign outgoing messages. After installation:

  1. Generate a DKIM key for your domain
  2. Add the public key as a TXT record in DNS
  3. Connect OpenDKIM with Postfix as a milter
  4. Test the signature by sending a message and checking headers

Step 7: Set Up SpamAssassin

SpamAssassin filters incoming messages and classifies them. Install it and connect it to Postfix to scan every message before delivery. Set the threshold to 5.0 as a starting point (any message scoring higher is classified as spam).

Step 8: Set Up Webmail

For browser-based email access, install Roundcube. Its interface is modern and supports IMAP fully. Install it on a subdomain such as webmail.yourdomain.com.

Testing the Server

After completing setup, test everything:

  • Send a message from the server to Gmail and check SPF and DKIM headers
  • Use mail-tester.com for a comprehensive rating
  • Verify the PTR record via MXToolbox
  • Test IMAP and SMTP connections from an email client

The Alternative: Managed Email Hosting

Setting up a mail server from scratch requires technical expertise and ongoing maintenance time. If you prefer a ready-made solution, CLOUD (cloud.net.sa) provides managed corporate email with Cloud Hosting. All technical configurations are pre-completed, backups are automatic, and technical support is available when needed.


Get Started

Want to try it yourself? Choose the right hosting plan or build your custom server with the specs you need.

Share