Update Mail.php

Moved the logic to module core to keep it clean