用MAILX 发送邮件

使用 25 端口发送 mail

编辑/etc/mail.rc 文件,添加以下信息
vi /etc/mail.rc

set from=xxx@163.com smtp=smtp.163.com
set smtp-auth-user=xxx@163.com smtp-auth-password=123456
set smtp-auth=login

:wq! #保存退出

echo "zabbix test mail" |mail -s "zabbix" yyy@163.com

#测试发送邮件,标题zabbix,邮件内容:zabbix test mail,发送到的邮箱:yyy@163.com
#这时候,邮箱yyy@163.com会收到来自xxx@163.com的测试邮件

使用 587 端口发送 mail

####创建目录,用来存放证书####
# mkdir -p /root/certs/163mail

####向163请求证书####
# echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /root/certs/163mail/163.crt

 

####添加一个证书到证书数据库中####
# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/certs/163mail -i /root/certs/163mail/163.crt

####添加一个证书到证书数据库中####
# certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/certs/163mail -i /root/certs/163mail/163.crt

 

####列出目录下证书####
# certutil -L -d /root/certs/163mail

然后前往163邮箱打开smtp并获取客户端授权码
网页正上方:设置→POP3/SMTP/IMAP

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

 

 set from=xxx@163.com
#set smtp=smtps://smtp.163.com:465
set smtp=smtps://smtp.163.com:587
set smtp-auth-user=xxx@163.com
set smtp-auth-password=********
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/certs/163mail

发送完邮件还有报错:证书不被信任,且命令行就此卡住,需要按键才能出现命令提示符
Error in certificate: Peer's certificate issuer is not recognized.

# cd /root/.certs/

 [root@PLAY .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt
Notice: Trust flag u is set automatically if the private key is present.

阿里云邮箱

echo -n | openssl s_client -connect smtp.qiye.aliyun.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /.certs/alimail/alimail.crt

certutil -A -n "GlobalSign SSL CA" -t "C,," -d /.certs/alimail -i /.certs/alimail/alimail.crt
certutil -A -n "GlobalSign SSL CA" -t "C,," -d /.certs/alimail -i /.certs/alimail/alimail.crt 

certutil -L -d /.certs/alimail

 

posted @ 2020-05-24 14:36  tamatama  阅读(158)  评论(0编辑  收藏  举报
GO TOP