1.通过msmtp可以调用外部的邮件服务器来进行邮件发送

安装msmtp

 

[root@zhu1 ~]# wget http://garr.dl.sourceforge.net/project/msmtp/msmtp/1.4.31/msmtp-1.4.31.tar.bz2

 

tar jxvf msmtp-1.4.31.tar.bz2cd msmtp-1.4.31./configure --prefix=/usr/local/msmtpmake && make install

2.创建配置文件

 

[root@zhu1 ~]# mkdir /usr/local/msmtp/etcvim /usr/local/msmtp/etc/msmtprcaccount defaulthost mail.iwgame.comport 25from zabbix@iwgame.comauth logintls offuser zabbix@iwgame.compassword zabbixlogfile /var/log/zabbix/msmtp.log

 

3.测试

 

[root@zhu1 ~]# /usr/local/msmtp/bin/msmtp zhujiangtao@iwgame.comdu diao han jiang xue #输入的内容,ctrl+d结束

这样便可在邮箱中收到邮件了

4.安装mutt

 

yum -y install mutt

5.创建配置文件

 

[root@jiankong-centos ~]# vi /etc/Muttrcset sendmail="/usr/local/msmrc/bin/msmtp"set use_from=yesset realname="zabbix@iwgame.com"set editor="vim"set charset="utf-8"set rfc2047_parameters=yes

6.测试

 

[root@jiankong-centos ~]# echo "wen jun neng you ji duo chou" | mutt -s 'ni hao' zhujiangtao@iwgame.com

 

在zabbix的配置文件中会指定脚本的存放目录,把zabbix通过脚本报警的脚本放在该目录下

 

[root@jiankong-centos alertscripts]# pwd/opt/zabbix/share/zabbix/alertscripts[root@jiankong-centos alertscripts]# ll-rwxr-xr-x. 1 root root   42 8月  12 10:05 sendemail.sh-rwxr-xr-x. 1 root root 1351 8月  12 15:11 sendmsg.py[root@jiankong-centos alertscripts]# nl sendemail.sh1  #!/bin/bash2  echo "$3" | mutt -s "$2" "$1"邮件报警脚本和短信报警脚本

msmtp详解:

msmtp 指令的参数:

--version :版本信息,默认的全局配置文件和用户配置文件

 

[root@zhu1 ~]# /usr/local/msmtp/bin/msmtp --versionmsmtp version 1.4.31Platform: i686-pc-linux-gnuTLS/SSL library: OpenSSLAuthentication library: built-inSupported authentication methods:plain cram-md5 external loginIDN support: enabledNLS: enabled, LOCALEDIR is /usr/local/msmtp/share/localeKeyring support: noneSystem configuration file name: /usr/local/msmtp/etc/msmtprcUser configuration file name: /root/.msmtprcCopyright (C) 2013 Martin Lambers and others.This is free software.  You may redistribute copies of it under the terms ofthe GNU General Public License 
.There is NO WARRANTY, to the extent permitted by law.

--help :显示帮助

-P :显示使用的配置信息