DBMail is an open source project to make a database backed mail system. It provides components to load and retrieve mail from the database, and plugs into your existing SMTP server. It can currently use either MySQL or PostgreSQL as the backend database.
It can provide IMAP and POP3 access to the database. There is also a webmail client which accesses the database directly for reading messages.