Learn SMTP. Use telnet to send an email. That is the basics. It gets more and more nuanced after that. Auth. Deliverability (avoiding looking like spam and doing dkim and spf). Dealing with retries and bounces. Writing valid mimes. If you want to be like an email service provider, you will have to deal with multi tenant issues too. These are the basics for sending mail. For receiving mail, you have spam report handling, delayed bounces, inbox validation, mime parsing, etc. Because of all this, most people just use something like postfix.