Email Server with API calls

Go the standard route.

  1. Set up a SMTP server for receiving mail
  2. Set up an IMAP server for storing mail
  3. 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.