Read up on Postfix (SMTP) and Dovecot (POP3 and IMAP). (Sendmail is available as an alternative to Postfix.) Additional services you'll want include MIMEDefang (general filter management), SpamAssassin (anti-spam), and ClamAV (anti-virus scanning). Other useful services include OpenDKIM (validates that mail really came from the domain it claims to have come from), Roundcube (web-based email client), and Certbot (acquire a LetsEncrypt cert for your mail servers). You might want OpenLDAP for authentication, identity management, and address books. Fail2ban can help keep the script kiddies out of your services. Running a mail server requires knowledge of many different services and awareness of many security issues. You have your work cut out for you.