add exception handling to email sending functionality