Click here to Skip to main content
12,065,888 members (27,765 online)
Click here to Skip to main content
Add your own
alternative version


38 bookmarked

Backing up MS Outlook emails along with Meta-data

, 4 Jun 2006
Rate this:
Please Sign up or sign in to vote.
Scans outlook inbox folder and put emails information in database. Also creates .msg file fore every message in Emails Folder. Finally it moves Email from inbox to inboxBackupFolder.

Sample screenshot Download sourcecode (804 kb)

Sample screenshot


Outlook Logger is a console base application that scans your MS Outlook Inbox folder and saves the meta-data of your emails in MS Access database For Example: sender information, Email Subject, Attachments Count, Message sent and Receive time, Message Importance etc. Further it also saves the TO,CC,BCC information for each email in another table.

Application creates an outlook .msg and save i Emails directory. Emails are saved in sub-folders named as recieved date of emails.

Finally it moves Email from inbox to "Personal Folders\InBoxBackup" Folder.

Outlook Redemption has been used to get rid of Security Prompts in  outlook.

Not a tough thing to do!! So move on...

Note: Following Steps to run application
1. Register redemption.dll (provided with code) using regsvr32 on your Computer.
2. Create Personal Folders\InBoxBackup Folder in outlook


Database Side:

Outlook logger stores the meta-data of emails in 'OutLook_DB.mdb' database that is located in \bin folder. Database contains the following four tables.

1) 'Outlook_logger_tmp' : Temporary Storage of EntryID of all emails in inbox.
2) 'Outlook_logger_message': Store Emails Meta-data as described above.
3) 'Outlook_logger_Recipients': Stores the information of Emails Recipients, as To,Bcc and CC.
4) 'Outlook_logger_Attachments': Attachments data of emails

EntryID is the property of Outlook that uniquely identifies each email (in a folder). I have appended sender email address to apply more uniqueness for example:


Every Email has its own ID and tracked against it. Linked in tables and also the .msg file name.

 a) Delete All Recs from outlook_logger_tmp table.
 b) Get EntryID for each email from Inbox in 'Outlook_logger_tmp'.
 c) Compare EntryIDs in outlook_logger_tmp with 'Outlook_logger_message' table and identify New Emails (EntryIDs).
 d) Save new EntryIDs in an ArrayList.

b. Start Processing each Email one by one
 a) Save Emails Meta-deta in outlook_logger_message table.
 b) Check if attachment then save the attachment metadata in 'OUTLOOK_LOGGER_ATTACHMENTS'.
 c) Save Email File
 d) Move Email in backup folder

Lets jump into source Code:

<FONT color=#0000ff></FONT>
<FONT color=#0000ff>

 <FONT size=2><P></FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> mainCode()</P><P></FONT><FONT color=#008000 size=2>'FIRST CHECK FOR DESTINATION FOLDER of Emails</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Not</FONT><FONT size=2> checkDirPath(destinationFolder) </FONT><FONT color=#0000ff size=2>Then</P></FONT><FONT size=2><P>Console.WriteLine("Destination directory " & destinationFolder & " - Not Accessable")</P><P></FONT><FONT color=#0000ff size=2>Exit</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Const</FONT><FONT size=2> olFolderInbox = 6</P><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> inboxFolder </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> Outlook.MAPIFolder = oNS.GetDefaultFolder(olFolderInbox)</P><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> sInboxItem </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> Redemption.SafeMailItem()</P><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> inboxItems </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> Outlook.Items = inboxFolder.Items</P><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> rCurrentUser </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> Redemption.SafeCurrentUser()</P><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> currentUserEmailAddr, insertQuery </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>'Get Current User Email Address</P></FONT><FONT size=2><P>currentUserEmailAddr = rCurrentUser.Address.ToLower</P><P>Console.WriteLine("Started Scanning Emails on : " & currentUserEmailAddr)</P><P></FONT><FONT color=#008000 size=2>'DELETE ALL MAILS EntryIDs DATA (OLD) FROM TEMP TABLE</P></FONT><FONT size=2><P>deleteTmpTable()</P><P></FONT><FONT color=#008000 size=2>'Store Inbox EntryIDs Emails in Tmp Table</P></FONT><FONT size=2><P>loadTmpTable(inboxItems)</P><P>Console.WriteLine("Total " & inboxItems.Count & " emails found in Inbox")</P><P></FONT><FONT color=#008000 size=2>'Store New Emails's EntryIDs </P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> mailIDs </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> ArrayList = getNewEntryIDs()</P><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> mailID </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> id </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>'Now Process Emails One by One</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>For</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Each</FONT><FONT size=2> mailID </FONT><FONT color=#0000ff size=2>In</FONT><FONT size=2> mailIDs</P><P></FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> inboxItems.Count <> 0 </FONT><FONT color=#0000ff size=2>Then</P></FONT><FONT size=2><P>sInboxItem.Item = inboxItems.GetFirst</P><P></FONT><FONT color=#0000ff size=2>Else</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Exit</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>For</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>While</FONT><FONT size=2> TypeName(sInboxItem.Item) <> "Nothing"</P><P>id = sInboxItem.EntryID & "-" & sInboxItem.SenderEmailAddress</P><P></FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> id = mailID </FONT><FONT color=#0000ff size=2>Then</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> msgRecvDate </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Date</FONT><FONT size=2> = </FONT><FONT color=#0000ff size=2>CDate</FONT><FONT size=2>(sInboxItem.ReceivedTime)</P><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> FolderName </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2> = DatePart(DateInterval.Year, msgRecvDate) & "-" & DatePart(DateInterval.Month, msgRecvDate) & "-" & DatePart(DateInterval.Day, msgRecvDate)</P><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> destSubFolder </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2> = destinationFolder & "\" & FolderName</P><P>MkFolder(destSubFolder)</P><P>logMessage(mailID, sInboxItem, currentUserEmailAddr, destSubFolder)</P><P></FONT><FONT color=#008000 size=2>'Save Recipients data</P></FONT><FONT size=2><P>saveRecipientsInfo(mailID, sInboxItem, "TO")</P><P>saveRecipientsInfo(mailID, sInboxItem, "CC")</P><P>saveRecipientsInfo(mailID, sInboxItem, "BCC")</P><P></FONT><FONT color=#008000 size=2>'Save Attachments Meta-Data</P></FONT><FONT size=2><P>saveAttachments(mailID, sInboxItem)</P><P></FONT><FONT color=#008000 size=2>'Save Message</P></FONT><FONT size=2><P>saveMessageFile(mailID, sInboxItem, destSubFolder)</P><P></FONT><FONT color=#008000 size=2>'Move Email to Backup Folder</P></FONT><FONT size=2><P>moveToBackup(sInboxItem)</P><P></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If</P></FONT><FONT size=2><P>sInboxItem.Item = inboxItems.GetNext()</P><P></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>While</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Next</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT></P> 
<P><FONT color=#0000ff size=2></FONT>
<P><FONT color=#0000ff size=2> </P>
<P><FONT color=#0000ff size=2> </P>


Main theme behind writing this article was to develop an understanding of working with MS Outlook in .Net and use of Outlook Redemption to get rid of security prompts in Outlook, when emails are accessed outside MS-Outook (with service pack installed).


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Ehsan Abbasi
Web Developer
Pakistan Pakistan
Author has Master's degree in Computer Science. Worked in VC++ earlier. Now working in .Net technologies.

Some Experience in Multimedia and E-Learning as well. Now a days he is developing software applications for Telecom and mobile sector.

You may also be interested in...

Comments and Discussions

Questionsource code print corrupted Pin
hjgode15-Aug-14 20:53
memberhjgode15-Aug-14 20:53 
Generalhiiiiiiii Pin
sunny12nov19854-Feb-11 20:15
membersunny12nov19854-Feb-11 20:15 
GeneralMy vote of 5 Pin
treesprite29-Jan-11 6:35
membertreesprite29-Jan-11 6:35 
GeneralThank you Pin
rtchandler252-Dec-09 10:41
memberrtchandler252-Dec-09 10:41 
GeneralC++ Pin
MPTP18-Jun-09 19:57
memberMPTP18-Jun-09 19:57 
GeneralThank you very much~! Pin
cotopboy Zhang17-Dec-08 6:29
membercotopboy Zhang17-Dec-08 6:29 
GeneralExcellent Pin
profpaul22-Mar-07 15:23
memberprofpaul22-Mar-07 15:23 
GeneralDatabase script Pin
skirby5531-May-06 10:55
memberskirby5531-May-06 10:55 
GeneralRe: Database script Pin
Ehsan Abbasi4-Jun-06 21:24
memberEhsan Abbasi4-Jun-06 21:24 
GeneralRe: Database script Pin
skirby555-Jun-06 5:15
memberskirby555-Jun-06 5:15 
Generalwaste of space Pin
Darka26-May-06 6:25
memberDarka26-May-06 6:25 
GeneralRe: waste of space Pin
Ehsan Abbasi28-May-06 20:36
memberEhsan Abbasi28-May-06 20:36 
GeneralRe: waste of space Pin
priestnall31-Aug-09 22:43
memberpriestnall31-Aug-09 22:43 
GeneralRe: waste of space Pin
Jonathan [Darka]31-Aug-09 23:01
memberJonathan [Darka]31-Aug-09 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160207.1 | Last Updated 5 Jun 2006
Article Copyright 2006 by Ehsan Abbasi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid