CentOS配置mailx通过465端口发送qq邮件

花门楼前见秋草,岂能贫贱相看老。这篇文章主要讲述CentOS配置mailx通过465端口发送qq邮件相关的知识,希望能为你提供帮助。
公司用的邮箱为腾讯企业邮箱,今天在阿里云主机测试邮件发送,发现使用默认的25端口,邮件发送失败,报连接超时
经nc 工具测试端口,发现smtp.exmail.qq.com服务器 25端口连接超时,465端口则连接正常

# nc -w 2 smtp.exmail.qq.com 25 < /dev/null & & echo "port is ok" Ncat: Connection timed out. # nc -w 2 smtp.exmail.qq.com 465 < /dev/null & & echo "port is ok" port is ok

随即准备配置mailx工具,准备使用465端口发邮件
系统:centos7
1、先停止系统默认的邮件工具
# systemctl disable postfix # systemctl stop postfix# systemctl disable sendmail # systemctl stop sendmail

如果不爽,直接删掉也行
2、安装mailx 包
# yum install mailx

so easy...
3、开始配置 修改配置文件mail.rc
# vim /etc/mail.rcset from=xxx@qq.com//发送的邮箱 set smtp=smtps://smtp.exmail.qq.com:465//smtp加端口 set smtp-auth-user=xxx@qq.com//发送的邮箱 set smtp-auth-password=passwd123//认证密码 set smtp-auth=login//默认login即可 set ssl-verify=ignore//ssl验证 忽略 set nss-config-dir=/root/.certs//证书所在目录,自定义

请求数字证书创建证书
# mkdir /root/.certs # echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne \'/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p\' > /root/.certs/qq.crt depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA verify return:1 depth=1 C = US, O = DigiCert Inc, CN = DigiCert Secure Site CN CA G3 verify return:1 depth=0 C = CN, ST = Guangdong Province, L = Shenzhen, O = Tencent Technology (Shenzhen) Company Limited, CN = *.exmail.qq.com verify return:1 DONE

添加证书到数据库中
# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/.certs -i /root/.certs/qq.crt # certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/.certs -i /root/.certs/qq.crt # cd/root/.certs/ # certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /root/.certs/./ -i qq.crt Notice: Trust flag u is set automatically if the private key is present.

列出指定的目录certdir的所有证书
# certutil -L -d /root/.certsCertificate NicknameTrust Attributes SSL,S/MIME,JAR/XPIGeoTrust SSL CAP,P,P

ls查看文件
# ls cert8.dbkey3.dbqq.crtsecmod.db

4、发送测试邮件
echo "邮件正文" | mail -s "邮件主题" xxx@163.com

其他方式
cat file.txt | mail -s "邮件主题" xxx@163.commail -s "邮件主题" xxx@163.com < file.txt

【CentOS配置mailx通过465端口发送qq邮件】发附件
mail -s "邮件主题"-a 附件.zip xxx@163.com < file.txt


    推荐阅读