配置软件源
ubuntu18.04上无法直接安装heirloom-mailx,需要添加软件源
sudo vi /etc/apt/sources.list
写入
deb http://cz.archive.ubuntu.com/ubuntu xenial main universe
安装heirloom-mailx
sudo apt-get update
sudo apt install heirloom-mailx
配置外部SMTP
Ubuntu18.04的配置文件为/etc/s-nail.rc,把下面几行放置在最后
set from="123456789@qq.com"
set smtp="smtps://smtp.qq.com:465"
set smtp-auth-user="123456789@qq.com"
set smtp-auth-password="ahkphxxabcbshabbga"
set smtp-auth=login
注意:1.第四行password是指的QQ邮箱授权码,不是密码,QQ邮箱授权码获取可以查看相关文章:https://jingyan.baidu.com/article/fedf0737af2b4035ac8977ea.html
2.from 和 smtp-auth-user邮箱要一致
测试
echo "邮件内容" | s-nail -s "邮件主题" xxx456@qq.com
或者
s-nail -s "邮件主题" 123xxx@qq.com < result.txt
原文链接:https://blog.csdn.net/mdx20072419/article/details/103901254