centos利用mail发送邮件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Yoga0301/article/details/82313397

centos利用mail发送邮件


安装mail

   yum install mailx -y

请求数字证书

root@PLAY ~]# mkdir -p /root/.certs/                           ####创建目录,用来存放证书
[root@PLAY ~]# echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt ####向163请求证书
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify return:1
depth=1 C = US, O = GeoTrust Inc., CN = GeoTrust SSL CA - G3
verify return:1
depth=0 C = CN, ST = Zhejiang, L = Hangzhou, O = "NetEase (Hangzhou) Network Co., Ltd", OU = MAIL Dept., CN = *.163.com
verify return:1
DONE
[root@PLAY ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt                  ####添加一个证书到证书数据库中
[root@PLAY ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt               ####添加一个证书到证书数据库中
[root@PLAY ~]# certutil -L -d /root/.certs                                                                                         ####列出目录下证书
Certificate Nickname Trust Attributes
SSL,S/MIME,JAR/XPI
GeoTrust SSL CA

 然后前往163邮箱打开smtp并获取客户端授权码

    网页正上方:设置→POP3/SMTP/IMAP

    网页左侧:客户端授权密码

网易邮箱获取客户端授权密码流程图

配置mail.rc

set from=xxx@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=XXX@163.com  #邮箱地址
set smtp-auth-password=XXXX  #客户端授权密码
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs #证书路径

发送邮件

  1. 发送文本
echo message3 | mail -v -s "This is the subject" xxx@163.com 
  1. 发送文件
echo "邮件内容" | mail -a 附件 -v -s “邮件标题" 收件人邮箱@qq.com

参考:

centos上mailx通过465端口发送邮件

猜你喜欢

转载自blog.csdn.net/Yoga0301/article/details/82313397
今日推荐