[Ubuntu] 架設郵件伺服器 (Postfix + Dovecot)
- 2023.10.18
- Linux Ubuntu 22.04
- mode
Postfix
sudo hostnamectl set-hostname a1go.ai
hostname -f
確認 hostname-
sudo apt install postfix
- General mail configuration type: Internet Site
- System mail name: a1go.ai
- DNS setting1Namecheap:
MAIL SETTINGS → Custom MX
→ Type: MX Record | Host: @ | Mail Server: a1go.ai | Priority: 0 | TTL: Automatic
※ Postfix 的 log 在 /var/log/mail.log
Dovecot
sudo apt install dovecot-core dovecot-lmtpd
sudo useradd vmail
sudo mkdir /var/mail/vhosts
sudo chown vmail:vmail /var/mail/vhosts
(把 owner 和 group 的 ownership 都改成vmail)sudo nano /etc/dovecot/conf.d/10-mail.conf
修改mail_location = maildir:/var/mail/vhosts/%d/%n
(user@domain – %n: user part, %d: domain part)sudo nano /etc/dovecot/conf.d/10-auth.conf
- !include auth-system.conf.ext → #!include auth-system.conf.ext
- #!include auth-static.conf.ext → !include auth-static.conf.ext
sudo nano /etc/dovecot/conf.d/auth-static.conf.ext
加入:# static userdb with shared uid and gid userdb { driver = static args = uid=vmail gid=vmail } # using password file passdb { driver = passwd-file args = /etc/dovecot/passwd }
- 新增 Dovecot User:
sudo sh -c "echo {user}@{domain}:{passwd}:::::: >> /etc/dovecot/passwd"
sudo nano /etc/dovecot/conf.d/10-master.conf
將以下部分service lmtp { unix_listener lmtp { #mode = 0666 } ... }
改動為:
service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { mode = 0600 group = postfix user = postfix } ... }
sudo nano /etc/postfix/main.cf
加入:virtual_mailbox_domains = a1go.ai virtual_transport = lmtp:unix:private/dovecot-lmtp
還要把 virtual_mailbox_domains(a1go.ai) 從 mydestination 刪除:
mydestination = localhost # $myhostname, a1go.ai, localhost.ai, , localhost
-
sudo service postfix restart
sudo /etc/init.d/dovecot restart
※ 讀取信件
sudo doveadm fetch -u {user}@{domain} text.utf8 MAILBOX INBOX
Ref
Last Updated on 2023/10/19 by A1go