I wrote a perl script which still ships with ACS 3.4, which is
called q.pl or queue-message.pl. It's made to be called from
qmail or sendmail, and basically just stuffs the email message
into a queue table in the database. You could probably easily modify it to stuff
into Postgres, since it uses the Perl DBI API.
it's documented a little bit in the ACS 3.4 documentation dir as
"email-handler".