Added email sending on error.