/usr/local/bin/maildayHTML:
#! /bin/bash

# requires smtpd_log_access_permit_actions = static:all in /etc/postfix/main.cf
# will not list emails sent to multiple users (not an issue for me)

if [ "$#" -eq 0 ];then
 echo “include pattern for user”
else
 TITLE=`gdate --date='yesterday' +'%d %B %Y'`
 echo "<!DOCTYPE html><html><head><title>$TITLE \"$1\"</title> <style>"
   echo 'table { border-collapse: collapse; }
   td,th { border-top: 1px solid black; border-bottom: 1px solid black; 
Padding: .5em; }
   tr { border-left: 1px black solid; border-right: 1px black solid; }
   </style></head><body><table>
   <tr>
     <th style="width:10em;">QUEUEID</th><th 
style="width:6em;">Time</th><th>From</th>
   </tr>’

  bzgrep -E 'DATA|\"from=\"' /var/log/maillog.0.bz2 | grep -v "<>"| \
    awk '{print $6"\t"$3"\t"$17"\t"$16}' | grep -v ESMTP | \
    grep -v "to=<backup" | column -t | sort -k 2 | grep "to=<$*" | \
    sed 's/from=<//g' | sed 's/>//g' |
    awk '{print "<tr><td>"$1"</td><td>"$2"</td><td>"$4"</td></tr>"}'

 echo "</table></body></html>"
fi
#EOF

And then for the user who want a daily report, I have the following in crontab

DAY=gdate +%d-%b-%Y
2 0 * * * /usr/local/bin/maildayHTML kremels | mutt -e 'set 
content_type=text/html' -s "DMR List $($DAY)” kremels+l...@kreme.com

(this obviously requires that gnu date and mutt be installed, but I believe 
this is also possible with straight sendmail, though more complicated)

I don’t know if any mail clients use the <title> from the HTML, but I figured 
I’d include it just in case.

I have a plain text version also, but it is far less readable, so everyone 
who’s been given the option has chosen the HTML. Just take out the echo

The email looks like this on Mail.app

<https://www.dropbox.com/s/t0lfrlpvvldm5ub/Screenshot%202016-04-04%2017.22.02.png?dl=0>

-- 
Clicked "Debug" button. Program still has bugs. Wtf? - Rich Seigel

Reply via email to