Ubuntu上安装heirloom-mailx:
sudo apt-get install heirloom-mailx
配置sudo vim /etc/nail.rc
添加网易163邮箱开放的需要认证的smtp服务器:
set from=用户名@163.com
set smtp=smtp.163.com
set smtp-auth-user=用户名
set smtp-auth-password=密码
set smtp-auth=login
等号两边不能有空格,被坑过
在用户的主目录下的.bashrc文件的最下面写上
echo '有人登录服务器' `date` `who` |mail -s "有用户登录服务器 `who | cut -d'(' -f2 | cut -d')' -f1`" 接收邮件的邮箱@qq.com
在命令行发邮件给QQ邮箱用户:
echo "邮件内容" | heirloom-mailx -s "邮件标题" xxxxx@qq.com
转载于:https://my.oschina.net/uxstone/blog/513639