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.
Asked
Active
Viewed 1.1k times
7

Skywalker
- 412
- 1
- 8
- 14
-
3Good luck sir this sounds like you're walking into a nightmare – Chris Marisic Jan 28 '10 at 21:39
-
1What's the point of storing the msg in a *binary* format in the db? I thought .msg's are text... – OMG Ponies Jan 28 '10 at 21:42
-
exactly - storing the .msg as NVARCHAR(MAX) would also allow you to apply fulltext searching to the mail messages.... not so much if you store it in a proprietary binary format. – marc_s Jan 28 '10 at 21:44
-
What about attachments? Are they stored as text? – JeffO Jan 29 '10 at 03:51
-
It is important that I am able to display the email in outlook again, hence the need to a .msg. I am pulling out other fields to store as metadata though. – Skywalker Jan 29 '10 at 14:37
2 Answers
2
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.

Mitchel Sellers
- 62,228
- 14
- 110
- 173
-
1I am pulling out the important bits and pieces to store as metadata. However, I want to be able to display the email back in Outlook. I am basically designing a replacement for public folders. – Skywalker Jan 28 '10 at 21:48
-
Oh, given that, you might just be out of luck. Sadly I cannot seem to find a way to do that operation in-memory. – Mitchel Sellers Jan 28 '10 at 21:50
-
Perhaps there is a way to create a virtual directory so the `MailItem` thinks it is saving itself to the disk while it is actually being loading into memory? – Skywalker Jan 28 '10 at 21:53
-
At that point, the overhead of simple file operations are most likely not going to be any worse than something to try and get that... – Mitchel Sellers Jan 28 '10 at 21:56
1
Possibly.
Depending on your setup, you can avoid Outlook and just use Exchange/SQL Server.
I've never tried it so YMMV

gbn
- 422,506
- 82
- 585
- 676
-
I don't really have access to the Exchange server and I am going to want the users to push only certain emails into the database – Skywalker Jan 29 '10 at 14:56
-
Might not have helped the OP, but you helped me immensely. Thank you! This is exactly what I was looking for :-). – dallasstar Oct 22 '13 at 23:47