refactoring mail  module