1.安装sendmail
yum install sendmail -y
systemctl status sendmail
# 查看sendmail运行状态
systemctl start sendmail
# 启动
systemctl enable sendmail
# 设置开机自启
systemctl is-enabled sendmail
# 查看是否设置开机自启
2.安装mailx
yum install mailx -y
3.发送邮件
3.1 通过文件发送
vim test.txt
hello world!!
mail -s 'mail test' 2647437068@qq.com < test.txt
3.2 通过管道符发送
echo "this is my test mail" | mail -s 'mail test2' 2647437068@qq.com
4.设置发件人信息
如果不设置发件人信息,上述发送邮件默认会使用linux当前登录用户名(root),通常会被当成垃圾邮件被拦截,取回之后才可以查看。
指定发件人邮箱信息命令:vim /etc/mail.rc,编辑内容如下:
vim /etc/mail.rc
set from=2647437068@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=2647437068@qq.com
set smtp-auth-password=nibojgkhlmhkbafbv
注意配置中的smtp-auth-password不是邮箱登录密码,是邮箱服务器开启smtp的授权码,每个邮箱开启授权码操作不同