email sending refactoring