Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing email messages in a database

What sort of database schema would you use to store email messages, with as much header information as practical/possible, into a database?

Assume that they have been fed into a script from the MTA and parsed into the relevant headers/body/attachments.

Would you store the message body whole in the database table, or split any MIME-parts apart? What about attachments?

like image 464
Alister Bulman Avatar asked Sep 15 '08 17:09

Alister Bulman


People also ask

How do I store email content in a database?

Suggestion: create a well defined table for storing e-mail with a column for each relevant part of a message: sender, header, subject, body. It is going to be much simpler later if you want to query, for example, by subject field.

How do I store emails in SQL?

you can use varchar as your data type for email column as emails are usually composed of letters, numbers and special characters. Show activity on this post. The right value of data lenght for the email field is database-agnostic.

How do I insert an email into a database?

Inserting email (file) attachments into the target database is just as easy as mapping the data from the email body. Simply select the desired attachment from the "Insert Mode" list. You can insert any type of file attachment into your database, whether it's pure binary data or documents.


2 Answers

You may want to check the architecture and the DB schema of "Archiveopteryx".

like image 165
Milen A. Radev Avatar answered Oct 20 '22 01:10

Milen A. Radev


You may want to use a schema where the message body and attachment records can be shared between multiple recipients on the message. It's not uncommon to see email servers where fully 50% of the disk storage is used by duplicate emails.

A simple hash of the body/attachment would be enough to see if that record was already in the database. However, you would still need to keep separate headers.

like image 33
Chase Seibert Avatar answered Oct 19 '22 23:10

Chase Seibert