Factor out email notification code.