Refactored entity encoding into mail class