fix email sending bugs