5) ubuntu安裝配置heirloom-mailx使用外部smtp發送外網email


1- 安裝

1.1- 添加heirloom-mailx apt源

cat /etc/apt/sources.list.d/mailx.list
deb http://cz.archive.ubuntu.com/ubuntu xenial main universe

1.2- 更新apt

apt update

1.3- 安裝heirloom-mailx

apt install heirloom-mailx -y

2- 配置

2.1- 配置外部發件郵箱

vim /etc/s-nail.rc  在最后加上:

###for 163郵箱
set from="xxxxx@163.com" #發件地址
set smtp="smtps://smtp.163.com:465" #smtp服務器
set smtp-auth-user="xxxxxx@163.com" #登錄發件地址
set smtp-auth-password="xxxx" #明文密碼
set smtp-auth=login #登錄方式,默認是login,也可以改成CRAM-MD5或PLAIN方式


###for outlook
set from="xxxx@outlook.com"
set smtp="outlook.office365.com:587"
set smtp-auth-user="xxxx@outlook.com"
set smtp-auth-password="xxxx" #明文密碼
set smtp-use-starttls #加密方式
set ssl-verify=ignore # 忽略ssl認證
set smtp-auth=login

###for QQ mail
set from="xxx@qq.com"
set smtp="smtps://smtp.qq.com:465"
set smtp-auth-user="xxx@qq.com"
set smtp-auth-password="ahkphxxabcbshabbga" #QQ郵箱授權碼
set smtp-auth=login

3- 常用命令

3.1- 發送郵件命令:

n:不讀入設置文件(本系統中是/etc/s-nail.rc)(這個文件允許用戶使用外部郵件傳輸代理而不是使用系統自帶的sendmail發送郵件)。
s:設置郵件的主題信息。
c:使用一個抄送列表。
b:使用一個密送列表。

3.2- 發送測試郵件

echo "內容"|s-nail -s "主題" xxxx@163.com,xxxx@outlook.com #多個郵箱用逗號隔開
#或者:
s-nail -s "郵件主題" xxx@163.com < result.txt

ps:加參數v可以看到mail輸出的詳細信息
s-nail -vs "郵件主題" xxx@163.com < result.txt

#發送帶附件郵件
s-nail -a 附件 -s "主題" 收件地址 < 文件(郵件正文.txt)
s-nail -a /xxx.tar.gz -s "主題" xxx@163.com < ./xxx.txt

#shell 當編輯器,編輯完內容后按Ctrl-D結束
s-nail -s '主題‘ xxx@163.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM