1、查看mailx是否安装
安装命令:
yum install mailx -y
查看是否安装:
which mailmail -V
2、修改配置
在邮箱中开启smtp服务,并生成授权码
修改阿里云服务器端的配置:
vim /etc/mail.rc
文件中加入以下参数:
set from=username@
set smtp=“smtps://:465”
set smtp-auth-user=username@
set smtp-auth-password=aaaaaaaaaaaa #授权码
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/
阿里云smtp的25端口是被封掉了,这里使用465加密端口
添加完成后cat查看无乱码即可
cat -A /etc/mail.rc
3、使用mail发送邮件测试
三种方式发送邮件:
命令行: mail -s “theme” addressee,回车后输入内容按Ctrl+D发送邮件.管道符: echo “mail main content” | mail -s “theme” addressee文件内容作为邮件内容: mail -s “theme” addressee < /tmp/t.txt
[root@yx01 ~]# echo 'hello' |mail -v -s "test" username@Resolving host . . . done.Connecting to 183.3.225.42:465 . . . connected.Error in certificate: Peer's certificate issuer has been marked as not trusted by paring DNS name: "*."Comparing DNS name: "993."Comparing DNS name: "993."Comparing DNS name: "993."Comparing DNS name: "993."Comparing DNS name: "993."Comparing DNS name: ""Comparing DNS name: ""Comparing DNS name: ""Comparing DNS name: ""Comparing DNS name: ""Comparing DNS name: ""SSL parameters: cipher=AES-128-GCM, keysize=128, secretkeysize=128,issuer=CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BEsubject=CN=*.,O=Shenzhen Tencent Computer Systems Company Limited,L=shenzhen,ST=guangdong,C=CN220 XMail Esmtp QQ Mail Server.>>> EHLO yx01250-250-PIPELINING250-SIZE 73400320250-AUTH LOGIN PLAIN250-AUTH=LOGIN250-MAILCOMPRESS250 8BITMIME>>> AUTH LOGIN334 VXNlcm5hbWU6>>> eXV4aWFuZzE5OTMwNzI1QHFxLmNvbQ==334 UGFzc3dvcmQ6>>> Z3dyeGp4YmFvc2p4ZGVlYQ==235 Authentication successful>>> MAIL FROM:<username@>250 OK.>>> RCPT TO:<username@>250 OK>>> DATA354 End data with <CR><LF>.<CR><LF>.>>> .250 OK: queued as.>>> QUIT221 Bye.
查看邮箱已经收到邮件
4、解决证书问题
上述步骤完成后,发送邮件虽然可以成功,但服务器终端会出现证书不被信任的回显
Error in certificate: Peer’s certificate issuer has been marked as not trusted by the.
完成下面步骤设置后不会出现上面的回显了
cd /etc/pki/nssdbecho -n | openssl s_client -connect :465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ./qq.crtcertutil -A -n "GeoTrust SSL CA" -t "C,," -d /etc/pki/nssdb/ -i /etc/pki/nssdb/qq.crtcertutil -A -n "GeoTrust Global CA" -t "C,," -d /etc/pki/nssdb/ -i /etc/pki/nssdb/qq.crtcertutil -L -d /etc/pki/nssdb/certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt