Reworked existing functions and added a function

Reworked executesql and email functions for better error handling and
printing. Also added emaillog function for emailing contents of log file
at the end of a script