log errors before sending the email