Email Server with API calls
Go the standard route.
- Set up a SMTP server for receiving mail
- Set up an IMAP server for storing mail
- Use an IMAP access library for a programming language of your choice to manipulate the mail store
For every point there a dozens of how-tos on the internet. And even better: for every point there are multiple exchangeable options. Because these are standards.