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.bz2
cd msmtp-1.4.31
./configure --prefix=/usr/local/msmtp
make && make install

2.创建配置文件

 

[root@zhu1 ~]# mkdir /usr/local/msmtp/etc
vim /usr/local/msmtp/etc/msmtprc
account default
host mail.iwgame.com
port 25
from zabbix@iwgame.com
auth login
tls off
user zabbix@iwgame.com
password zabbix
logfile /var/log/zabbix/msmtp.log

 

3.测试

 

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

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

4.安装mutt

 

yum -y install mutt

5.创建配置文件

 

[root@jiankong-centos ~]# vi /etc/Muttrc
set sendmail="/usr/local/msmrc/bin/msmtp"
set use_from=yes
set 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.sh
1  #!/bin/bash
2  echo "$3" | mutt -s "$2" "$1"
邮件报警脚本和短信报警脚本

msmtp详解:

msmtp 指令的参数:

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

 

[root@zhu1 ~]# /usr/local/msmtp/bin/msmtp --version
msmtp version 1.4.31
Platform: i686-pc-linux-gnu
TLS/SSL library: OpenSSL
Authentication library: built-in
Supported authentication methods:
plain cram-md5 external login
IDN support: enabled
NLS: enabled, LOCALEDIR is /usr/local/msmtp/share/locale
Keyring support: none
System configuration file name: /usr/local/msmtp/etc/msmtprc
User configuration file name: /root/.msmtprc
Copyright (C) 2013 Martin Lambers and others.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

--help :显示帮助

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