ubuntu18.04 安裝和配置Postfix發送郵件

一、安裝psotfix

  • 安裝過程詢問環境時選擇Internet Site,詢問hostname時填寫你的郵件域名服務
sudo apt-get install postfix
# sudo dpkg-reconfigure postfix 重新配置

在這裏插入圖片描述

  • 安裝mailutils工具包
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

  • 連接本地SMTP服務
telnet localhost 25
  • 發一封郵件給incoming用戶,郵件信息如下
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    # 查詢postfix狀態
sudo postfix start    # 啓動postfix服務
  • 登陸incoming用戶,查詢接收到的郵件
su - incoming
mail
  • 你會看到以下信息
"/var/mail/incoming": 1 message 1 unread
>U   1 root@localhost                           59/2842  Re: Some issue

在這裏插入圖片描述

四、配置postfix使用Maildir-style mailboxes

  • 添加配置,重啓postfix服務
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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章