Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Outlook emails in a Microsoft SQL Server database

I am using c# to write an Outlook 2007 add-in to store emails in a SQL Server 2005 database. I would like to be able to store the entire .msg file in a varbinary(MAX) field. Is there a way to do this without having to use the Outlook MailItem's SaveAs() method to save to a temp file and then read the file back in? I will need to transfer a large number of emails to the database and would prefer to avoid costly disk reads and writes.

like image 619
Skywalker Avatar asked Jan 28 '10 21:01

Skywalker


People also ask

How do I save an email body in a SQL database?

Just use varchar(max) as it will be the easiest option to keep all data in the database so you can migrate, replicate or whatever the database and everything will be kept intact.

What is the best data type for email in SQL?

VARCHAR is the best data type to be used for email addresses as Emails vary a lot by length. NVARCHAR is also an alternative but I would recommend it to use only if the email address contains extended chars and keep in mind that it requires double amount of storage space as compared to VARCHAR.


1 Answers

If you are looking to actually store it as a .msg format file, without trying to re-write this yourself, I would say that you are looking at going the route you mentioned.

Personally I would go to storing bits and pieces of the email, but that depends on exactly what you are going to do with it. Storing a MSG file in an DB in my opinion isn't really anything of value. now your use case might prove otherwise.

like image 140
Mitchel Sellers Avatar answered Nov 09 '22 22:11

Mitchel Sellers