CentOS7服务器默认安装了mailx
#如果没有请执行 yum install mailx #编辑发送的配置文件 vi /etc/mail.rc
注意如果使用qq发送邮件,请向登陆你的qq邮箱设置中,配置你的个人发送权限
获得个人的 授权码
# This is the configuration file for Heirloom mailx (formerly # known under the name "nail". # See mailx(1) for further options. # This file is not overwritten when 'make install' is run in # the mailx build process again. # Sccsid @(#)nail.rc 2.11 (gritter) 8/2/08 set from=limexxxxxx@qq.com set smtp=smtps://smtp.qq.com:465 set smtp-auth-user=xxxxx6xxxxxxx@qq.com set smtp-auth-password=kbdykrqqjytxbfdh set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/root/.certs
:wq 保存 /etc/mail.rc
#还需要添加邮箱证书到本地 # 创建证书目录 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 # 在命令行里发送邮件会提示“Error in certificate: Peer's certificate issuer is not recognized.”这样的证书没有获得认可的警告提示,需要执行下面指明受信任证书、防报错的命令 certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs -i ~/.certs/qq.crt
如果出现
Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI GeoTrust SSL CA C,, [root@122 ~]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs -i ~/.certs/qq.crt Notice: Trust flag u is set automatically if the private key is present.
说明配置成功,快发送一个邮件到自己邮箱看看吧
-s 加邮箱标题 ,记得使用自己的qq 发送哦
echo “邮件内容lmk” | mail -s “来自我的服务器” 734449600@qq.com
配置完成