[svc]msmtp+mutt发附件,发邮件给多个人
环境: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" xxx@qq.com
Muttrc配置
修改/etc/Muttrc配置如下
set editor="vim" set from="xx@qq.com" 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 xx@qq.com #对方从这个地址收邮件 auth login user xx@qq.com #发送者邮箱 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:'xx@qq.com -- xx@qq.com
1,用mutt同时发邮件给多个人
/tmp/mailmon.txt 1213213@qq.com zhangsan@cc.com lisi@cc.com 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:'mon@pp100.com -- $i done
2,用mutt发附件 见上