armbian发送邮件:s-nail

实现命令行发邮件,使用163邮箱的SMTP。本文记录了部署过程。

安装s-nail

apt install s-nail

设置

nano /etc/s-nail.rc
在文件最后加上:

1
2
3
4
5
set from=user@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth=login
set smtp-auth-user=user@163.com
set smtp-auth-password=此处不是邮箱密码,而是smtp服务提供的授权码!!!

发送测试邮件

echo "Successful" | s-nail -s "hello?" xxxxxxxx@qq.com
xxxxxxxx@qq.com发送一个标题为hello?,正文是Successful。
输出:

1
2
3
4
5
6
7
8
root@onecloud:/etc# echo "Successful" | s-nail -s "hello?" ease_lee@qq.com
s-nail: Warning: variable superseded or obsoleted: smtp
s-nail: Warning: variable superseded or obsoleted: smtp-auth-user
s-nail: Warning: variable superseded or obsoleted: smtp-auth-password
s-nail: The empty (default) command is ignored here, but has arguments: 1
s-nail: Obsoletion warning: please do not use *smtp*, instead assign a smtp:// URL to *mta*!
s-nail: Obsoletion warning: Use of old-style credentials, which will vanish in v15!
s-nail: Please read the manual section "On URL syntax and credential lookup"

添加附件
echo "Successful" | s-nail -s "hello?" -a joke.txt xxxxxxxx@qq.com

虽然有警告,邮件还是发送出去了。

新设置

nano /etc/s-nail.rc
在文件最后加上:

1
2
3
4
set from="user@163.com"
set smtp-auth=login
set mta=smtps://user:password@smtp.163.com:465 #smtp服务器端口是465
set v15-compat #必须要

输出:
s-nail: The empty (default) command is ignored here, but has arguments: 1

邮件能正常发送。附件较大的邮件只能发送到163邮箱,发到QQ邮箱会被退信。163邮箱和QQ邮箱做为smtp服务器都需要授权码。
在WebServerAutoBackup的备份脚本中第294行加上以下代码就可以把每天的备份包以附件的形式发送到163邮箱(附件较大,只能发到这里):

1
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Backup Successful" | s-nail -s "[$(date +"%Y-%m-%d %H:%M:%S")]服务器备份文件" -a ${SAVE_DIR}/backup.$NOW.zip user@163.com