目录
概述:
在linux服务器上(我这里是Centos7.x)我们一般是通过mail命令来进行邮件发送的,mail, mailx都是收发邮件用的,类似浏览器的作用,可以用作邮件用户代理(MUA,Mail User Agent);
而sendmail是做邮件服务器的,类似apache, nginx的作用,可以用作邮件传输代理(MTA,Mail Transport Agent)
实验准备:
1)测试是否连接外网
[root@localhost ~]# ping -c4 baidu.com
2)保证防火墙和selinux已关闭
一、linux用户发送给外网用户(qq邮箱)
1.首先在qq邮箱官网生成授权码
微信扫码发送短信验证------发送成功点击‘我已发送’
2.安装sendmail和mailx
[root@localhost ~]# yum -y install sendmail mailx
3.启动
[root@localhost ~]# systemctl start sendmail
4.编辑配置/etc/mail.rc
[root@localhost ~]# vim /etc/mail.rc
##此步骤相当于登录qq邮箱账户
set from=148******@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=148*******@qq.com
set smtp-auth-password=**********
set ssl-verify=ignore
set nss-config-dir=/root/.certs
set smtp-auth=login
5.颁发建立nss-config-dir证书
接下来我们需要生成nss-config-dir指定的证书文件,输入如下指令生成证书
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
查看证书是否生成
[root@localhost ~]# ls /root/.certs/
6.验证:
发送邮箱命令
------------------------------------------------------------------------------
方式一:
echo '邮件内容' | mail -s '邮件标题' xxx接收邮件的邮箱地址
方式二:
mail -s '邮件标题' 收件人邮箱 < xxx文件
选项:
-s 为邮箱标题
示例:
[root@localhost ~]# echo '邮件内容' | mail -s '邮件标题' 137415955@qq.com ##接收者邮箱号
##由于证书是自己颁发的,所以会报不安全,但不影响发送邮件
登录邮箱查看:
成功接收到邮件!