bin/mail(bin/mailx)默認使用本地sendmail發送郵件,本地的機器必須安裝並啓動Sendmail服務,配置比較麻煩,不穩定。vim
下文經過修改配置文件可使用外部SMTP服務器來發送郵件。服務器
以網易郵箱爲例。配置
一、vim /etc/mail.rc #( /etc/nail.rc),追加以下文字密碼
set from=from@163.com im
set smtp=smtp.163.com配置文件
set smtp-auth-user=from@163.com word
set smtp-auth-password=aaaa文件
set smtp-auth=loginvi
說明:auth
from是發送的郵件地址
smtp是發生的外部smtp服務器的地址
smtp-auth-user是外部smtp服務器認證的用戶名
smtp-auth-password是外部smtp服務器認證的用戶密碼
smtp-auth是郵件認證的方式
配置後執行以下命令:
cat context.txt| mail -s "tes the smtp mail" toooo@163.com
userfasdf@163com是收件人地址,content.txt裏面是郵件正文.