Add msg file to or email to pst in outlook using Microsoft.Office.Interop.Outlook.
To Add physical MSG files to PST and generate PST we need to follow below steps:-
Add Com library Microsoft.Office.interop.outlook
-
Create object of COM Object MailItem,Namespace,Application
-
ns(object of namespace) = app(object of Applciation).GetNamespace("MAPI")
ns.AddStoreEx(newPstFileLocation, OlStoreType.olStoreUnicode)
-
For Each store As Store In ns.Session.Stores
If store.FilePath = newPstFileLocation Then
newPST = store
End If
Next
-
Object of MAPI Folder Ex: oFolder
-
oFolder = newPST.GetRootFolder
-
.mail = CType(ns.Session.OpenSharedItem(filetobeprocessed), MailItem)
mail.Move(folderInbox)
folderInbox is object of Simple inbox folder and we are adding moving
files to folderInbox.