How can I close the mail function in terminal?
To read the mail you have, use the mail command. man mail will give you instructions.

To delete all mail without reading it, run

sudo rm /var/mail/$USER/*