Don't worry about the CGI's, everything you can do via the website you can do via the command line by passing stuff to the "external command file" (nagios.cmd).
SO to do this, hit up this site:
nagios.org/developerinfo/ext ... ndlist.php
As you can see, the first two listed may be the ones you need. Click them and it'll give a nice little example script of what you need to echo to nagios.cmd.
As for how you're going to have an email reply cause a script to be run which echo's stuff to nagios.cmd, you're on your own there! I'm positive it can be done as we do something similar with our RT ticketing system (maybe look for examples by looking up RT documentation?)