mail delivery refactor