Add exception handling and stdout/err logging for email