Refactoring and add mail adapter