管理服务器时我们经常需要写一些监测脚本,然后在出问题的时候通过邮件来通知
SMTP(Simple Mail Transfer Protocol)简易邮件传输通讯协议
SMTP服务器是遵循SMTP协议的发送邮件服务器,用来发送或中转你发出的电子邮件。可以理解为就是用来寄信的,而且大多数SMTP服务器也是免费的。
授权码作为密码
系统postfix服务要开启
vim /etc/mail.rc
在文件最后插入:
set from=345678910@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=345678910
set smtp-auth-password=授权码
set smtp-auth=login
from是发送的邮件地址
smtp是发生的外部smtp服务器的地址
smtp-auth-user是外部smtp服务器认证的用户名
smtp-auth-password是外部smtp服务器认证的用户密码(授权码)
smtp-auth是邮件认证的方式
echo ‘test’ | mail -s ‘test‘ 345678910@qq.com
mail -s "标题" 邮件地址 < 文件
mail -s "test" 345678910@qq.com </etc/hosts
echo "正文" | mail -s "test" 345678910@qq.com
原文:https://www.cnblogs.com/lxfpy/p/10869377.html