CentOS mailx client

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS mailx client相关的知识,希望对你有一定的参考价值。

想通过Linux监控系统状况,并邮件自动报警,可以使用脚本处理,通过自带的mailx工具来发出警告 邮件

安装mailx

[email protected]/1 # yum -y install mail
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.163.com
 * extras: mirrors.yun-idc.com
 * updates: mirrors.yun-idc.com
base                                                                                                                    | 3.7 kB     00:00     
extras                                                                                                                  | 3.4 kB     00:00     
updates                                                                                                                 | 3.4 kB     00:00     
updates/primary_db                                                                                                      | 4.0 MB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mailx.x86_64 0:12.4-8.el6_6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
 Package                         Arch                             Version                                 Repository                      Size
===============================================================================================================================================
Installing:
 mailx                           x86_64                           12.4-8.el6_6                            base                           235 k

Transaction Summary
===============================================================================================================================================
Install       1 Package(s)

Total download size: 235 k
Installed size: 452 k
Downloading Packages:
mailx-12.4-8.el6_6.x86_64.rpm                                                                                           | 235 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mailx-12.4-8.el6_6.x86_64                                                                                                   1/1 
  Verifying  : mailx-12.4-8.el6_6.x86_64                                                                                                   1/1 

Installed:
  mailx.x86_64 0:12.4-8.el6_6                                                                                                                  

Complete!

确认安装结果(版本必须是12.4以上,不然发邮件需要sendmail服务)

[email protected]/1 # rpm -qa|grep mailx
mailx-12.4-8.el6_6.x86_64

[email protected]/1 # mail -V
12.4 7/29/08

配置外部邮箱(发件人)

[email protected]/0 # vim /etc/mail.rc

set [email protected] smtp=smtp.139.com
set [email protected] smtp-auth-password=******
set smtp-auth=login

说明:

from: 对方收到邮件时显示的发件人
smtp: 指定第三方发送邮件的smtp服务器地址
smtp-auth: SMTP的认证方式。默认是LOGIN,也可改为CRAM-MD5或PLAIN方式
smtp-auth-user: 第三方发邮件的用户名
smtp-auth-password: 用户名对应密码

mail命令

[email protected]/2 # mail --help
mail: illegal option -- -
Usage: mail -eiIUdEFntBDNHRV~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users

注:部分系统参数稍有差异,最好看帮助

1) 无邮件正文

mail -s "主题" 收件地址

mail -s "测试"  [email protected]

2) 有邮件正文

mail -s "主题" 收件地址< 文件(邮件正文.txt)

mail -s "邮件主题"  [email protected] < /data/findyou.txt

echo "邮件正文" | mail -s 邮件主题 收件地址

echo "邮件正文内容" | mail -s "邮件主题"  [email protected]

cat 邮件正文.txt | mail -s 邮件主题 收件地址

cat  /data/findyou.txt | mail -s "邮件主题"  [email protected]

3) 带附件

mail -s "主题" 收件地址 -a 附件 < 文件(邮件正文.txt)

mail -s "邮件主题"  [email protected] -a /data/findyou.tar.gz < /data/findyou.txt

以上是关于CentOS mailx client的主要内容,如果未能解决你的问题,请参考以下文章

centos 7 mailx邮件发送

centos7 利用mailx发送邮件

Centos 配置mailx使用外部smtp发送邮件

centos7 outlook mailx配置

CentOS 7 mailx工具使用外部邮箱发邮件

centos上mailx通过465端口发送邮件