Setting Up a Mail Server with Postfix and Dovecot

Setting Up a Mail Server with Postfix and Dovecot

This guide sets up a basic mail server: Postfix handles sending/receiving (SMTP) and Dovecot handles retrieval (IMAP).

Prerequisites

  • A domain with proper DNS: MX record, A record, and rDNS (PTR) configured
  • Ports 25, 587, 993 open in your firewall

Step 1 — Install Postfix and Dovecot

apt update
apt install postfix dovecot-core dovecot-imapd -y

During Postfix setup, select Internet Site and enter your domain name.

Step 2 — Configure Postfix

nano /etc/postfix/main.cf
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost, $mydomain
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_use_tls=yes

Step 3 — Configure Dovecot

nano /etc/dovecot/dovecot.conf
protocols = imap
mail_location = maildir:~/Maildir
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.yourdomain.com/privkey.pem

Step 4 — Set Up DNS Records for Deliverability

# SPF:
TXT @ "v=spf1 ip4:YOUR_SERVER_IP ~all"

# DKIM: Install opendkim and add the public key
apt install opendkim opendkim-tools -y

Step 5 — Open Firewall Ports

ufw allow 25    # SMTP
ufw allow 587   # Submission
ufw allow 993   # IMAPS
ufw allow 110   # POP3 (optional)

Step 6 — Restart Services

systemctl restart postfix dovecot

Test with swaks

apt install swaks -y
swaks --to test@gmail.com --from you@yourdomain.com --server localhost
  • 0 Bu dökümanı faydalı bulan kullanıcılar:
Bu cevap yeterince yardımcı oldu mu?

İlgili diğer dökümanlar

Understanding Your Server's Network Configuration

Understanding Your Server's Network Configuration Knowing how to read and manage your server's...

Setting Up Reverse DNS (rDNS/PTR Record)

Setting Up Reverse DNS (rDNS / PTR Record) A reverse DNS (PTR) record maps your IP address back...

How to Configure a Static IP Address on Linux

Configuring a Static IP Address on Linux Dedicated servers typically have a static IP configured...

Setting Up Nginx as a Reverse Proxy

Setting Up Nginx as a Reverse Proxy A reverse proxy forwards incoming requests to a backend...

How to Configure DNS Records for Your Domain

Configuring DNS Records for Your Domain DNS records tell the internet how to reach your domain....