一、安裝psotfix
- 安裝過程詢問環境時選擇Internet Site,詢問hostname時填寫你的郵件域名服務
sudo apt-get install postfix
sudo apt-get install mailutils
- 如果域名沒有dns指向,在/etc/hosts指向到本地
127.0.0.1 sentry.tlwlmy.net
二、添加用戶保存郵件列表
sudo useradd -m -s /bin/bash incoming
sudo passwd incoming
三、測試本地的SMTP server
telnet localhost 25
ehlo localhost
mail from: root@localhost
rcpt to: incoming@localhost
data
Subject: Re: Some issue
Sounds good!
.
quit
- 如果連接SMTP返回Connection refused或者其他錯誤,檢查postfix是否在運行
sudo postfix status
sudo postfix start
su - incoming
mail
"/var/mail/incoming": 1 message 1 unread
>U 1 root@localhost 59/2842 Re: Some issue
四、配置postfix使用Maildir-style mailboxes
sudo postconf -e "home_mailbox = Maildir/"
sudo service postfix restart
- 登陸incoming用戶,新建郵件文件目錄(改成使用庫heirloom-mailx自動新建)
su - incoming
mkdir /home/incoming/Maildir
MAIL=/home/incoming/Maildir
- 跟之前發郵件一樣,發一封郵件給incoming用戶
- 如果使用mail的時候,返回錯誤Maildir: Is a directory,你當前mail版本不支持Maildir style mailboxes,安裝heirloom-mailx庫,重新嘗試上面的步驟
sudo apt-get install heirloom-mailx
五、參考
- https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/doc/administration/reply_by_email_postfix_setup.md