How to Set Up a Postfix Mail Server on a UK VPS: Complete Guide

Why Run Your Own Mail Server on a UK VPS?

Running your own mail server gives you complete control over your email infrastructure. No third-party reading your emails. No per-user pricing that scales with headcount. No data leaving UK jurisdiction.

For UK businesses that handle sensitive communications—legal firms, healthcare providers, financial services—hosting your own email on a UK VPS ensures your data never leaves the country, which simplifies GDPR compliance.

In this guide, we'll set up a full email stack on a Hostingowy UK VPS including:

  • Postfix (SMTP server for sending mail)
  • Dovecot (IMAP/POP3 server for receiving mail)
  • SPF, DKIM, and DMARC (email authentication to prevent spoofing)
  • Roundcube (webmail interface — optional)

Prerequisites

  • A UK VPS from Hostingowy (any plan works, $5/mo Starter is sufficient for small teams)
  • Ubuntu 24.04 LTS
  • A domain name (e.g., yourcompany.com)
  • DNS access to add MX, SPF, DKIM, and DMARC records

Step 1: Set Up DNS Records

Before installing anything, configure your DNS. These records tell the internet that your VPS is authorised to send email for your domain.

MX Record

Type: MX
Name: @ (or yourdomain.com)
Value: mail.yourdomain.com
Priority: 10

A Record for Mail Subdomain

Type: A
Name: mail
Value: (your VPS IP address)

PTR Record (Reverse DNS)

Contact your hosting provider to set a PTR record for your VPS IP pointing to mail.yourdomain.com. Hostingowy sets PTR records on request—just open a support ticket.

SPF Record

Type: TXT
Name: @
Value: "v=spf1 mx a:mail.yourdomain.com -all"

DKIM Record

We'll generate the DKIM key in Step 4 and add the record then.

DMARC Record

Type: TXT
Name: _dmarc
Value: "v=DMARC1; p=quarantine; rua=mailto:postmaster@yourdomain.com"

Step 2: Install Postfix and Dovecot

SSH into your VPS and run:

# Update package list
sudo apt update

# Install Postfix, Dovecot, and supporting packages
sudo apt install postfix postfix-mysql dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd -y

# During Postfix installation, select "Internet Site"
# Set "System mail name" to: yourdomain.com

Step 3: Configure Postfix

Edit the main Postfix configuration file:

sudo nano /etc/postfix/main.cf

Add or modify these settings:

# Basic settings
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4

# TLS settings
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# Mailbox settings
home_mailbox = Maildir/
mailbox_command = 

# Restrictions
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

# Enable submission port (587)
submission inet n - n - - smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

Apply the changes:

sudo systemctl restart postfix

Step 4: Configure Dovecot

sudo nano /etc/dovecot/dovecot.conf
# Protocols
protocols = imap pop3 lmtp

# Authentication
auth_mechanisms = plain login

# Mail location
mail_location = maildir:/var/mail/vhosts/%d/%n

# SSL
ssl = required
ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key

Create virtual mail directories and a test user:

# Create directory structure
sudo mkdir -p /var/mail/vhosts/yourdomain.com
sudo groupadd -g 5000 vmail
sudo useradd -g vmail -u 5000 vmail -d /var/mail -s /bin/false
sudo chown -R vmail:vmail /var/mail

# Add a test email user
sudo useradd -m -s /bin/bash admin@yourdomain.com
sudo passwd admin@yourdomain.com

Restart Dovecot:

sudo systemctl restart dovecot

Step 5: Generate DKIM Keys

Install OpenDKIM to sign outgoing emails:

sudo apt install opendkim opendkim-tools -y

Generate your DKIM key pair:

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

Get your DKIM public key to add to DNS:

sudo cat /etc/opendkim/keys/yourdomain.com/mail.txt

This will output something like:

mail._domainkey IN TXT "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4G..."

Add this as a DNS TXT record:

Type: TXT
Name: mail._domainkey
Value: "v=DKIM1; h=sha256; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4G..."

Step 6: Test Your Mail Server

Send a test email from your server:

echo "Subject: Test Email from UK VPS

Hello! This email was sent from my Hostingowy UK VPS." | sendmail youremail@gmail.com

Check your Gmail inbox (or spam folder). If it landed in spam, your SPF, DKIM, or DMARC records may need adjustment.

For comprehensive testing, use these tools:

Email Deliverability Checklist

CheckWhy It MattersStatus
PTR record setReceiving servers verify your IP resolves to your domain⚪ Not set (contact Hostingowy support)
SPF record publishedAuthorises your VPS to send email for your domain⚪ Add to DNS
DKIM key generated + publishedDigitally signs your emails to prove authenticity⚪ Generate and publish
DMARC policy setTells receivers how to handle unauthenticated email⚪ Add to DNS
TLS enabled (port 587)Encrypts email in transit✅ Configured above
Warm up IPNew IPs have lower reputation—send gradually⚪ Send 5-10/day for first week

Common Issues and Fixes

Emails Going to Spam

  • Check SPF, DKIM, and DMARC records with online validators
  • Verify your PTR record matches your sending domain
  • New IPs need warming—don't send bulk emails immediately

Connection Refused on Port 25

Many UK hosting providers block port 25 by default. Hostingowy does not block port 25, but some residential ISPs do. If you're testing from home, use port 587 (submission) instead.

Authentication Failures

Make sure Dovecot SASL is running and Postfix is configured to use it. Check logs:

sudo tail -f /var/log/mail.log

Security Considerations

Running a mail server comes with responsibilities:

  • Monitor logs — Watch for failed login attempts and spam relaying
  • Rate limiting — Configure Postfix to limit outgoing emails per user
  • Regular updates — Keep Postfix, Dovecot, and OpenDKIM updated
  • Backup — Your emails are now your responsibility. Set up regular backups.
  • Fail2ban — Install and configure Fail2ban to block brute force attacks

For compliance with UK GDPR, ensure you have:

  • A data retention policy for emails
  • Encryption at rest for stored emails
  • Access controls for mail directories

Alternative: Use Hostingowy + Transactional Email Service

If full mail server management sounds like too much overhead, many UK businesses use a hybrid approach:

  • Transactional emails (password resets, notifications) → SendGrid, Mailgun, or Amazon SES
  • Internal/corporate email → Google Workspace or Microsoft 365
  • Application-specific emails → Self-hosted Postfix on a Hostingowy VPS

This gives you the best of both worlds: professional deliverability for customer-facing emails and full control for internal or compliance-sensitive communications.

Summary

Setting up a Postfix mail server on your UK VPS is achievable in under an hour. The key to good deliverability is proper DNS configuration—SPF, DKIM, DMARC, and PTR records matter more than any server tweak.

Start with the checklist above, test with Mail Tester, and gradually warm up your IP. Within a week, you'll have a fully functional mail server running on UK soil with complete data sovereignty.

Deploy Your UK VPS in Under 60 Seconds

All Hostingowy plans include NVMe storage, cloud firewall, and UK-based support. From $5/mo.

Get Started →
Hostingowy Engineering

Hostingowy is a UK-based VPS hosting provider. We build infrastructure for UK businesses that care about performance, compliance, and data sovereignty.