refactor mail sending