Guide to Setting Up an Email Server on a Hong Kong Server
Setting up an efficient, stable, and secure email server on a Hong Kong server allows you to break free from reliance on third-party email services and take full control of your email data. This article will detail the key steps and configuration points in the setup process, making it easy for you to get started even if it’s your first attempt.
Installing Necessary Components
A complete email system cannot function without the following core components:
- MTA (Mail Transfer Agent): Responsible for sending and relaying emails, we choose the powerful Postfix
- MDA (Mail Delivery Agent): Responsible for delivering emails to the user’s mailbox directory, here we use Postfix’s built-in local delivery function
- IMAP/POP3 Server: Responsible for providing an interface for email clients to retrieve emails, we choose Dovecot
First, use SSH to log in to your Hong Kong server and install the above components:
sudo apt update
sudo apt install postfix postfix-pcre dovecot-imapd dovecot-pop3d
Configuring Postfix
Postfix’s main configuration file is /etc/postfix/main.cf
, modify the following key parameters:
myhostname = mail.yourdomain.com
mydestination = $myhostname, yourdomain.com, localhost
home_mailbox = Maildir/
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
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
Among them, mydestination
specifies the domain names for which Postfix receives emails, home_mailbox
specifies the storage format and path of the user’s mailbox, and the smtpd_sasl_*
and smtpd_tls_*
parameters are used to configure SMTP authentication and encryption.
Configuring Dovecot
Dovecot’s main configuration file is /etc/dovecot/dovecot.conf
, uncomment the following line:
listen = *, ::
Edit /etc/dovecot/conf.d/10-mail.conf
, specify the mail storage path:
mail_location = maildir:~/Maildir
Edit /etc/dovecot/conf.d/10-auth.conf
, configure SMTP authentication:
auth_mechanisms = plain login
!include auth-system.conf.ext
Edit /etc/dovecot/conf.d/10-master.conf
, add authentication for postfix smtp:
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
}
Starting Services
After the configuration is complete, restart Postfix and Dovecot:
sudo service postfix restart
sudo service dovecot restart
Check the service status to ensure a successful start:
sudo service postfix status
sudo service dovecot status
Creating Email Accounts
To send and receive emails, you need to create a system account for each user. For example, to create a user named john:
sudo useradd -m john
sudo passwd john
Now john can send and receive emails using the email address john@yourdomain.com. Replace yourdomain.com with your own domain name.
Configuring DNS Records
Finally, don’t forget to add the following records to your domain’s DNS settings, pointing the mail server to your Hong Kong server:
yourdomain.com. MX 10 mail.yourdomain.com.
mail.yourdomain.com. A Server IP
Adding anti-spam records such as SPF and DKIM can further improve the credibility of your mailbox and reduce the probability of being misjudged as spam. There are many online tools that can help you quickly generate these records.
At this point, a fully functional email system has been set up. You can use email clients such as Foxmail and Thunderbird, or Webmail systems such as Roundcube and Rainloop to send and receive emails. A privately deployed email server is no less functional and performant than any commercial email service provider. You no longer have to worry about privacy data leakage or unilateral service shutdowns.