code for sending mail and adding summary stats.