RedHat/CentOS下mail命令使用介绍

本文详细介绍了在RedHat/CentOS内网和公网环境下如何使用mail命令,包括mailx的安装、postfix服务的启动与配置,以及不同情况下的邮件发送测试,如无正文、含正文及带附件的邮件发送。

一、内网环境下

1.安装mailx

yum install mailx

2.启动postfix服务

systemctl enable postfix
systemctl start postfix
systemctl status postfix

3.测试

echo "Hello!" | mail -s "Title" root@localhost

在这里插入图片描述
常用命令参数如下:
在这里插入图片描述

二、公网环境下

1.安装mailx

yum install mailx

2.配置mailx

#无需启动postfix服务

vim /etc/mail.rc
#在结尾处添加:
set from=abc@163.com
set smtp=smtp.163.com
set smtp-auth-user=abc@163.com
set smtp-auth-password=******
set smtp-auth=login

3.发送邮件测试

echo "Content" | mail -s "Title" abc@163.com

4.其他

mail命令 可以使用查看具体更多的使用方法

mail --h 

a、无邮件正文

mail -s "Title"  abc@163.com

b、有邮件正文

从message.txt文本导入

mail -s "Title"  abc@163.com < /root/message.txt 

或者

cat /root/message.txt  | mail -s "Title"  abc@163.com

直接“ ”键盘输入内容

echo “输入内容” |   mail -s "Title"  abc@163.com

c 、带附件的邮件

添加附件attach.rar

mail -s "Title"  abc@163.com  -a  /root/attach.rar 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值