利用 CentOS 7.6 发送邮件

利用 CentOS 7.6 发送邮件

今天摸索了一下用linux发电子邮件,网上查找了许多资料,终于成功了,做个笔记留着以后忘记了看。

1.我用的是阿里云的云服务器 CentOS 7.6 64位,因为阿里云把25端口封了,所以这里使用TSL方式,绕过25端口发送邮件;

2.首先输入以下命令安装mailx服务
yum  install  mailx -y
3.接着是获取证书,这里使用的是qq邮箱,如果用163邮箱,只需把第二句命令中的smtp.qq.com:465 换为smtp.163.com:465即可
[root@iZ3xc1s1h8mye7Z ~]# mkdir .certs

[root@iZ3xc1s1h8mye7Z ~]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /root/.certs/qq.crt

[root@iZ3xc1s1h8mye7Z ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/.certs -i /root/.certs/qq.crt

[root@iZ3xc1s1h8mye7Z ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/.certs -i /root/.certs/qq.crt

[root@iZ3xc1s1h8mye7Z ~]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /root/.certs/./ -i /root/.certs/qq.crt

Notice: Trust flag u is set automatically if the private key is present.

[root@iZ3xc1s1h8mye7Z ~]# ls /root/.certs/

qq.crt  cert8.db  key3.db  secmod.db

[root@iZ3xc1s1h8mye7Z ~]# certutil -L -d /root/.certs

Certificate Nickname                                         Trust Attributes

                                                             SSL,S/MIME,JAR/XPI

4.输入vim /etc/mail.rc命令,配置mail.rc文件

set from=xxxooo@qq.com     #发邮件的qq号
set smtp=smtps://smtp.qq.com:465   #邮件服务器
set smtp-auth-user=xxxooo@qq.com  #获得授权码的邮箱
set smtp-auth-password=你的授权码
set smtp-auth=login #默认login即可
set ssl-verify=ignore   #ssl认证方式
set nss-config-dir=/root/.certs   #证书所在目录

5.输入命令进行测试,测试结果如图所示(message是我创建的一个文件,里面是发送的内容)

[root@iZ3xc1s1h8mye7Z ~]# mailx -s "邮箱测试" xxxxx@qq.com < message

在这里插入图片描述

6.获取QQ邮箱授权码的操作如下

  • 进入QQ邮箱,点击左上角的设置,再点击账户
    在这里插入图片描述
  • 开启SMTP服务,点击生成授权码,随后验证手机即可获取授权码
    在这里插入图片描述
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值