第一种:通过自带邮件服务postfix方式
centos6:
/etc/init.d/postfix start #启动postfix邮件服务
lsof -i :25 #查看服务是否启动,smtp服务默认端口为25
chkconfig postfix on #添加为开机自启动
chkconfig --list postfix #查看开机自启动是否设置成功
echo "test"|mail -s "test" xxxxxxx@qq.com #发送测试邮件检测是否正常发送
mailq #查看邮件发送队列
centos7:
systemctl start postfix #启动postfix邮件服务
lsof -i :25 #查看服务是否启动,smtp服务默认端口为25
systemctl enable postfix #添加为开机自启动
systemctl list-unit-files|grep postfix #查看开机自启动是否设置成功
echo "test"|mail -s "test" xxxxxxx@qq.com #发送测试邮件检测是否正常发送
mailq #查看邮件发送队列
第二种:利用第三方服务商提供服务
这里用qq邮箱作为示例
yum install -y mailx #安装mailx服务
sed -i "set from=xxx@qq.com\nset smtp=smtp.qq.com\nset smtp-auth-user=xxx@qq.com\nset smtp-auth-password=xxx\nset smtp-auth=login" >>/etc/mail.rc #添加配置信息,xxx需要改成自己的邮件信息
echo "test"|mail -s "test" xxxxxxx@qq.com #发送测试邮件检测是否正常发送
mailq #查看邮件发送队列
注意:阿里云由于屏蔽了25端口,如果需要使用需要申请开放25端口,或者使用ssl方式发送邮件,具体操作自行百度。