Factor out common email code