LINUX 发送邮件(例子qq邮件)

Linux
本次测试 使用云主机 ,配置 liunx发送邮件至qq邮箱中

1、前往QQ邮箱,在设置-账户-下开启SMTP和获取授权码

2、安装mailx
[root@JD .certs]# yum -y install mailx
[root@JD learn_shell]# which mail
/usr/bin/mail


3、停⽌服务:
service sendmail stop
chkconfig sendmail off
[root@JD ~]# service sendmail stop
Redirecting to /bin/systemctl stop  sendmail.service
Failed to stop sendmail.service: Unit sendmail.service not loaded.
[root@JD ~]# chkconfig sendmail off
error reading information on service sendmail: No such file or directory


4、启动postfix服务:
service postfix start
chkconfig postfix on
postfix check
systemctl status postfix
[root@JD ~]# service postfix start
Redirecting to /bin/systemctl start  postfix.service
[root@JD ~]# chkconfig postfix on
Note: Forwarding request to 'systemctl enable postfix.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/postfix.service to /usr/lib/systemd/system/postfix.service.
[root@JD ~]# postfix check
[root@JD ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-08-23 11:07:54 CST; 31s ago
 Main PID: 2145 (master)
   CGroup: /system.slice/postfix.service
           ├─2145 /usr/libexec/postfix/master -w
           ├─2147 pickup -l -t unix -u
           └─2148 qmgr -l -t unix -u

Aug 23 11:07:52 JD systemd[1]: Starting Postfix Mail Transport Agent...
Aug 23 11:07:53 JD postfix/postfix-script[2143]: starting the Postfix mail system
Aug 23 11:07:54 JD postfix/master[2145]: daemon started -- version 2.10.1, configuration /etc/postfix
Aug 23 11:07:54 JD systemd[1]: Started Postfix Mail Transport Agent.

5、调整参数:
[root@JD ~]# vi /etc/postfix/main.cf
添加:inet_interfaces = all


6、生成证书
# 创建证书目录
[root@JD ~]# mkdir -p /root/.certs/
[root@JD ~]# cd .certs/
[root@JD .certs]# ll
total 0
#获取证书内容
[root@JD .certs]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.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, OU = www.digicert.com, CN = GeoTrust RSA CA 2018
verify return:1
depth=0 C = CN, ST = Guangdong, L = Shenzhen, O = Tencent Technology (Shenzhen) Company Limited, OU = R&D, CN = pop.qq.com
verify return:1
DONE
[root@JD .certs]# ll
total 4
-rw-r--r-- 1 root root 2529 Aug 23 15:46 qq.crt
# 添加证书到数据库
[root@JD .certs]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[root@JD .certs]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[root@JD .certs]# ll
total 80
-rw------- 1 root root 65536 Aug 23 15:47 cert8.db
-rw------- 1 root root 16384 Aug 23 15:47 key3.db
-rw-r--r-- 1 root root  2529 Aug 23 15:46 qq.crt
-rw------- 1 root root 16384 Aug 23 15:47 secmod.db
# 列出指定目录下的证书
[root@JD .certs]# certutil -L -d /root/.certs

Certificate Nickname                                         Trust Attributes
                                                             SSL,S/MIME,JAR/XPI

GeoTrust SSL CA                                              C,,  
# 标记新人证书、防报错
[root@JD .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
Notice: Trust flag u is set automatically if the private key is present.


7、编辑mail的配置文件
set from=xxx@qq.com         #发送邮件后显示的邮件发送方
set smtp=smtps://smtp.qq.com:465     #qq smtp邮件服务器
set smtp-auth-user=877747xxxx@qq.com  # 你的qq邮箱
#授权码
set smtp-auth-password=lmpzzmmxxxxxx  # 你的qq邮箱密码(设置页面加密后的授权码)
set smtp-auth=login        # 动作、登录
set ssl-verify=ignore          # 忽略ssl验证
set nss-config-dir=/root/.certs      # 证书路径

8、测试
#不带附件的
[root@JD .certs]# echo "来自liunx的第二封邮件" | mail -s " title" 87774xxxx@qq.com

9、#带附件发送邮件到QQ邮箱
[root@JD learn_shell]#  echo "发送带一个附件过来" |mail -s "来自linux的邮件" -r "from:LIUNX1 <877747xxxx@qq.com>" -a /root/learn_shell/awk.log 87774xxxxx@qq.com
———————————
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值