搭建郵件發送這麼簡單的一個功能,我在阿里雲ECS上來回倒騰了幾天,並且先後使用sendmail、postfix、heirloom-mailx等多種發送郵件的軟件。但總是出現各種各樣的錯誤。查找了百度和谷歌以及阿里雲開放論壇,終於搞定了,網上的資料好分散,查來查去都是相同內容,索引我把我搭建的經過寫出來,希望以後別有人掉坑裏了
下面我直接描述郵件發送成功的經過:
1、安裝heirloom-mailx
apt install heirloom-mailx
2、配置外部SMTP
我的ECS是Ubuntu16.04 ,配置文件爲/etc/s-nail.rc,把下面幾行放置在最後
如果不配置端口發送可以使用
set [email protected]
set smtp=smtp.163.com
set [email protected]
set smtp-auth-password=123456
set smtp-auth=login
如果配置端口則
set from="[email protected]"
set smtp="smtps://smtp.163.com:465"
set smtp-auth-user="[email protected]"
set smtp-auth-password="123456"
set smtp-auth=login
或者
set from="[email protected]"
set smtp="smtps://smtp.163.com:465"
set smtp-auth-user="[email protected]"
set smtp-auth-password="123456"
set smtp-auth=login
注:以上三種配置都可以嘗試
3、發送
echo 'this is test' | mail -s "test email." [email protected]