Linux发送接收邮件

目录

一、实验

1.linux用户发送给linux中的其它用户

 2.linux用户发送给外网用户


一、实验

1.linux用户发送给linux中的其它用户

(1)使用命令 yum install -y sendmail 安装sendmail软件

 (2)使用yum install -y mailx 安装 mailx软件

 (3)使用命令systemctl start sendmail启动sendmail(此过程消耗时间)

 (4)root用户发送邮件内容为"This is first email" 标题为 "email"给root用户

 (5)在root用户使用命令mail查看邮件

N表示此邮件为未读;1,2表示编号;root表示发送用户;时间;email表示主题

(6)输入编号即可查看详细信息

 (7)q键退出

 2.linux用户发送给外网用户

(1)首先在163邮箱中获取自己的提权码

     登录邮箱,在首页的设置里面打开pop3/smtp/imap

 (2)在开启服务IMAP/SMTP后点击开启即可获得授权码

 (3)在/etc/mail/rc文件中配置以下信息

 71 #开启ssl
 72 set ssl-verify=ignore
 73 
 74 #下方输入证书目录,下方为centos系统证书默认位置,也自行生成证书并指定
 75 
 76 set nss-config-dir=~/.certs
 77 
 78 # 下方填入你配置的第三方smtp服务器的地址及端口,如果使用的是云服务器,安全组需要开放465端口(入>    口和出口)
 79 
 80 set smtp=smtps://smtp.163.com:465            
 81 
 82 # 认证方式
 83 
 84 set smtp-auth=login
 85 
 86 # 下方输入用于发送邮件的邮箱账号
 87 
 88 set smtp-auth-user=7jjw@163.com
 89 
 90 # 下方输入上方邮箱的客户端授权码
 91 
 92 set smtp-auth-password=授权码
 93 
 94 # 设置发信人邮箱和昵称
 95 
 96 set from=7jjw@163.com
 97 

(4)配置邮箱证书

因为需要 163邮箱的 SSL 证书,所以我们还需要手动的获取163邮箱的证书保存到本地指定的目录里以备调用和验证,具体命令如下:

[root@localhost .certs]# echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.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, CN = GeoTrust RSA CN CA G2
verify return:1
depth=0 C = CN, ST = zhejiang, L = hangzhou, O = "NetEase (Hangzhou) Network Co., Ltd", CN = *.163.com
verify return:1
DONE
[root@localhost .certs]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil: could not add certificate to token or database: SEC_ERROR_ADDING_CERT: Error adding certificate to database.
[root@localhost .certs]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
certutil: could not add certificate to token or database: SEC_ERROR_ADDING_CERT: Error adding certificate to database.
[root@localhost .certs]# certutil -L -d /root/.certs

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

GeoTrust SSL CA                                              C,,  
GeoTrust Global CA                                           P,P,P

为了防止出现前文所说的发送邮件警告提示,还需要进入邮箱 SSL 证书存放目录 /root/.certs 里执行如下命令:

[root@localhost .certs]# cd /root/.certs/
[root@localhost .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.

开启postfix

systemctl start postfix

(5)使用命令echo "This is second email" | mail -s "email" 用户名  发送邮件

 (6)登录163邮箱查看收到的邮件

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值