随笔 - 6  文章 - 0  评论 - 1  阅读 - 6381

Linux配置mail实现发送邮件(以centos7.0为例)

一、关闭或卸载sendmail和postfix服务

1
2
3
4
5
6
7
8
9
10
11
12
#检查是否存在
[root@agent ~]# which sendmail
/sbin/sendmail
[root@agent ~]# which postfix
/sbin/postfix
#删除
[root@agent ~]# yum remove postfix -y
#检查
[root@agent ~]# which sendmail
/usr/bin/which: no sendmail in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@agent ~]# which postfix
/usr/bin/which: no postfix in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)  

二、获取自己邮箱的授权码(需要有一个授权码,用来调用自己的邮箱,用来发送信息,以163邮箱为例)

步骤一:

 

 步骤二:

 

 步骤三:

 

 三、安装相应的包

1
2
3
#检查是否存在,如果不存在则下载
[root@agent ~]# rpm -qa | grep mailx
[root@agent ~]# yum install mailx -y 

四、配置文件

1
2
3
4
5
6
7
8
9
10
#创建备份
[root@agent ~]# cp /etc/mail.rc /etc/mail.rc.bak
[root@agent ~]# cat /etc/mail.rc
set from=lucille_chu@163.com  #对方收到邮件时显示的发件人
set stmp=stmp.163.com  #邮箱服务器地址
set smtp-auth-user=lucille_ye@163.com  #邮箱账号
set smtp-auth-password=TGSBXXXXXXXXDC  #邮箱授权码
set smtp-auth=login  #stmp的认证方法
set ssl-verify=ignore  #忽略认证
set nss-config-dir=/etc/maildbs  #证书文件目录 

五、生成证书文件

1
2
3
4
5
6
7
[root@agent ~]# mkdir /etc/maildbs && certutil -N -d /etc/maildbs
Enter a password which will be used to encrypt your keys.
The password should be at least 8 characters long,
and should contain at least one non-alphabetic character.
 
Enter new password:
Re-enter password:  

六、发送邮件

1
2
[root@localhost ~]# echo this is a test | mail -s "test" 3089308419@qq.com
[root@localhost ~]# mail -s "test" 3089308419@qq.com < abc #这是一个文件名称,文件名称内部的内容就是邮件内容

 

posted on   小楚同学  阅读(761)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示