you either need to trigger a script when mail arrives in a particular mailbox (i have no idea how to do this) OR you need to write a CRON job to periodically check a particular mailbox for mail and then process the mail (i also have no idea how to do that).
strictly speaking, this is not a question about databases, but about coding. try posting there.