环境:centos6.7 x86-64
内网有web服务器(curl可展示目录)
#预安装软件
yum install lrzsz ntpdate sysstat dos2unix wget telnet tree -y
#下载软件
cd /usr/local/src
wget http://192.168.x.x/msmtp-1.4.32.tar.bz2
[ $? -eq 0 ] || exit 1 #安装msmtp
tar jxvf msmtp-1.4.32.tar.bz2
cd msmtp-1.4.32
./configure -prefix=/usr/local/msmtp
make
make install #拷贝msmtrc配置
mkdir -pv /usr/local/msmtp/etc/ && cd /usr/local/msmtp/etc/
wget http://192.168.x.x:/config/msmtprc
[ $? -eq 0 ] || exit 1
cp msmtprc /root/.msmtprc #安装mutt
yum install mutt -y
rpm -qa|grep mutt #复制mutt配置
mv /etc/Muttrc /etc/Muttrc.ori
cd /etc && wget http://192.168.x.x:/config/Muttrc
[ $? -eq 0 ] || exit 1
#安装成功后会收到一份邮件
echo "test from `ifconfig`" |mutt -s "test" [email protected]
Muttrc配置
修改/etc/Muttrc配置如下
set editor="vim"
set from="[email protected]"
set realname="发件人"
set sendmail="/usr/local/msmtp/bin/msmtp"
set use_from=yes
msmtp配置
defaults
logfile /usr/local/msmtp/msmtp.log
account test
host smtp.exmail.qq.com #发送者邮箱服务器地址
from [email protected] #对方从这个地址收邮件
auth login
user [email protected] #发送者邮箱
password xx #发送者邮箱密码
account default: test
port 25
tls off
重头戏来了
0,用mutt发邮件给一个人
/bin/cat /tmp/access.log | /usr/bin/mutt -s "top traffic of day: $(date +%F)" -a /tmp/etc.tar.gz -e 'set content_type="text/plain"' -e 'my_hdr from:'[email protected] -- [email protected]
1,用mutt同时发邮件给多个人
/tmp/mailmon.txt
[email protected]
[email protected]
[email protected] for i in `/bin/cat /tmp/mailmon.txt`
do
/bin/cat $mondir/mon.log | /usr/bin/mutt -s "top traffic of day: '$day'" -a /tmp/mon*.zip -e 'set content_type="text/plain"' -e 'my_hdr from:'[email protected] -- $i
done
2,用mutt发附件 见上