Refactoring of add mail funtion