NewCode CLOUD — 20% off your first month on all cloud VPSClaim

How to Set Up a Mail Server on Hong Kong VPS: Postfix, Dovecot & DKIM (2026)

· 5 min read

Self-hosting a mail server on a Hong Kong VPS gives your business complete control over email infrastructure — your own domain, no per-seat SaaS fees, and data that stays on your own servers. This guide deploys a complete mail server stack: Postfix (MTA), Dovecot (IMAP), SpamAssassin (spam filtering), and DKIM/DMARC (email authentication) — the combination that keeps your outbound email out of spam folders.

Important consideration before starting: Self-hosted mail servers require significant ongoing maintenance (spam filtering, IP reputation management, TLS certificate renewal). For small teams, Google Workspace or Zoho Mail may be more practical. Self-hosting makes most sense for teams with technical capacity, data sovereignty requirements, or very high email volume where per-seat costs are significant.


Prerequisites

  • A Hong Kong VPS with a clean, dedicated IP address (not a shared IP previously used for spam)
  • A domain name with DNS control
  • Port 25 must be open — confirm with your provider that outbound SMTP port 25 is not blocked (some providers block it by default for new VPS)
  • Reverse DNS (PTR record) for your VPS IP configured to match your mail hostname

Check Port 25 and Reverse DNS

# Verify port 25 is open outbound
telnet gmail-smtp-in.l.google.com 25
# Should connect — if connection refused, contact Server.HK support to open port 25

# Check your current PTR record
dig -x YOUR_VPS_IP +short
# Should return: mail.yourdomain.com (we'll set this up next)

Step 1: Configure Hostname and DNS

# Set server hostname to your mail server name
hostnamectl set-hostname mail.yourdomain.com
echo "YOUR_VPS_IP mail.yourdomain.com mail" >> /etc/hosts

DNS Records Required

Record Type Name Value Purpose
A mail.yourdomain.com YOUR_VPS_IP Mail server hostname
MX yourdomain.com mail.yourdomain.com (priority 10) Receive email
PTR YOUR_VPS_IP mail.yourdomain.com Reverse DNS (set via VPS control panel)
TXT (SPF) yourdomain.com v=spf1 ip4:YOUR_VPS_IP ~all Authorise your IP to send
TXT (DMARC) _dmarc.yourdomain.com v=DMARC1; p=quarantine; rua=mailto:dmarc@yourdomain.com Email policy

Configure the PTR record through Server.HK’s control panel or by contacting support — this is the reverse DNS record that maps your IP back to your hostname. Most receiving mail servers check this and reject mail from IPs without a matching PTR.


Step 2: Install Postfix (SMTP/MTA)

apt update && apt upgrade -y
DEBIAN_FRONTEND=noninteractive apt install -y postfix postfix-mysql

# During installation wizard:
# Mail server configuration type: Internet Site
# System mail name: yourdomain.com

Configure /etc/postfix/main.cf

<code">cat > /etc/postfix/main.cf << 'EOF'
# Basic settings
myhostname = mail.yourdomain.com
myorigin = /etc/mailname
mydomain = yourdomain.com
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
inet_interfaces = all
inet_protocols = all

# TLS for inbound (receiving)
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.yourdomain.com/privkey.pem
smtpd_tls_security_level = may
smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache

# TLS for outbound (sending)
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1

# SMTP restrictions (reduce spam relaying)
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination,
    reject_unknown_recipient_domain

# SASL authentication (for sending via this server)
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous

# Mailbox delivery
home_mailbox = Maildir/
mailbox_size_limit = 0

# Message size limit (50MB)
message_size_limit = 52428800
EOF

# Get TLS certificate
apt install -y certbot
certbot certonly --standalone -d mail.yourdomain.com

systemctl restart postfix

Step 3: Install Dovecot (IMAP)

<code">apt install -y dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd

cat > /etc/dovecot/dovecot.conf << 'EOF'
protocols = imap pop3 lmtp
listen = *, ::

ssl = required
ssl_cert = </etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.yourdomain.com/privkey.pem
ssl_min_protocol = TLSv1.2

mail_location = maildir:~/Maildir

auth_mechanisms = plain login

userdb {
    driver = passwd
}
passdb {
    driver = pam
}

service auth {
    unix_listener /var/spool/postfix/private/auth {
        group = postfix
        mode = 0660
        user = postfix
    }
}

service lmtp {
    unix_listener /var/spool/postfix/private/dovecot-lmtp {
        group = postfix
        mode = 0600
        user = postfix
    }
}
EOF

systemctl enable --now dovecot

Step 4: Configure DKIM Signing

<code">apt install -y opendkim opendkim-tools

mkdir -p /etc/opendkim/keys/yourdomain.com
opendkim-genkey -s mail -d yourdomain.com -D /etc/opendkim/keys/yourdomain.com/
chown -R opendkim:opendkim /etc/opendkim/keys/

cat > /etc/opendkim.conf << 'EOF' Domain yourdomain.com KeyFile /etc/opendkim/keys/yourdomain.com/mail.private Selector mail Socket inet:12301@localhost RequireSafeKeys false EOF # Add to Postfix main.cf cat >> /etc/postfix/main.cf << 'EOF'
# DKIM signing
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:localhost:12301
non_smtpd_milters = inet:localhost:12301
EOF

# Get your DKIM public key to add to DNS
cat /etc/opendkim/keys/yourdomain.com/mail.txt
# Add this TXT record to your DNS: _domainkey.mail.yourdomain.com

systemctl enable --now opendkim
systemctl restart postfix

Step 5: Install SpamAssassin

<code">apt install -y spamassassin spamc

# Configure SpamAssassin
cat >> /etc/spamassassin/local.cf << 'EOF' required_score 5.0 rewrite_header Subject [SPAM] report_safe 0 use_bayes 1 bayes_auto_learn 1 EOF # Integrate with Postfix cat >> /etc/postfix/master.cf << 'EOF'
spamassassin unix -     n       n       -       -       pipe
    user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
EOF

systemctl enable --now spamassassin
systemctl restart postfix

Step 6: Create Mail Users

<code"># Create system user for each email address
useradd -m -s /bin/bash john
echo "john:StrongMailPassword!" | chpasswd

# Create Maildir structure
su - john -c "mkdir -p ~/Maildir/{cur,new,tmp}"

# Test sending
echo "Test from Hong Kong VPS" | mail -s "Test" john@yourdomain.com

# Verify delivery
ls -la /home/john/Maildir/new/

Step 7: Open Required Firewall Ports

<code">ufw allow 25/tcp    # SMTP (receiving mail from other servers)
ufw allow 465/tcp   # SMTPS (sending with SSL)
ufw allow 587/tcp   # Submission (sending with STARTTLS)
ufw allow 993/tcp   # IMAPS (reading mail over SSL)
ufw allow 995/tcp   # POP3S
ufw reload

Step 8: Test Email Deliverability

<code"># Send a test email to a Gmail address and check headers
echo "Test" | mail -s "Deliverability Test" your-gmail@gmail.com

# Check these tools online:
# - mail-tester.com (score your email — aim for 10/10)
# - mxtoolbox.com (verify SPF, DKIM, DMARC records)
# - Google Postmaster Tools (monitor reputation with Gmail)

Check Mail Logs for Delivery Issues

<code">tail -f /var/log/mail.log

# Common issues:
# "Relay access denied" → smtpd_relay_restrictions misconfiguration
# "Connection refused" → port 25 blocked by provider
# "SPF check failed" → SPF record incorrect
# "DKIM verification failed" → DKIM DNS record not propagated yet

Web Mail Interface: Roundcube

<code">apt install -y roundcube roundcube-mysql

# Configure Roundcube database
mysql -u root -p << 'SQL'
CREATE DATABASE roundcube;
CREATE USER 'roundcubedb'@'localhost' IDENTIFIED BY 'RoundcubePass!';
GRANT ALL ON roundcube.* TO 'roundcubedb'@'localhost';
SQL

# Initialise Roundcube database
mysql -u roundcubedb -p roundcube < /usr/share/roundcube/SQL/mysql.initial.sql

# Configure Nginx virtual host for Roundcube
# Point to /var/lib/roundcube/public_html (standard PHP virtual host)

Conclusion

A self-hosted mail server on a Hong Kong VPS with Postfix, Dovecot, DKIM, and SpamAssassin delivers professional email for your domain with complete data control. The critical success factors are PTR record configuration (matching your hostname), complete DKIM/SPF/DMARC DNS records, and maintaining good IP reputation by monitoring outbound spam. Test with mail-tester.com after setup — a 10/10 score confirms your configuration will reach inboxes reliably.

Host your own email: Browse Server.HK Hong Kong VPS plans — contact support to confirm port 25 availability and PTR record configuration for your VPS IP before deployment.

Related articles

More in VPS & ServersServer setup guides