安裝sendmail后,發郵件一直沒有成功,因此卸載sendmail后,安裝heirloom-mailx。
# unbuntu 18.04和20.04移除了heirloom-mailx,需要另外配置軟件源 vim /etc/apt/sources.list # 加入 deb http://cz.archive.ubuntu.com/ubuntu xenial main universe # 安裝heirloom-mailx apt-get update apt-get install -y heirloom-mailx apt-get install -y mailutils # 安裝mailutils時,會彈出圖形化安裝界面,選擇Internet Site,System mail name 的值應該和ubuntu中hostname保持一致,如karl
# hostnamectl set-hostname karl
# 配置外部SMTP
配置外部SMTP,將如下幾行加入/etc/s-nail.rc文件最后面
set from="1106438132@qq.com" set smtp="smtps://smtp.qq.com:465" set smtp-auth-user="1106438132@qq.com" set smtp-auth-password="cgnbhnhftaenhdaj" set smtp-auth=login # auth-password是郵箱授權碼,不是郵箱密碼,需登錄郵箱后查看
# 測試郵件發送 echo "test_context" |s-nail -s "test_sub" karlkiller@icloud.com