Reputation: 113946
I have a directory hierarchy full of EML/MSG email data files. These files can be imported into MS Outlook 2010 (desktop version) one at a time, but I am looking for a way to automate this. I need to create each folder as an Outlook folder, and import email datafiles into these Outlook folders. Anyone aware of an Outlook 2010 API that allows for creating folders & importing files?
Upvotes: 1
Views: 2604
Reputation: 66215
To create new folders in Outlook, use MAPIFolder.Folders.Add
.
Outlook Object Model does not directly support importing EML or MSG files (or any other files for that matter).
For MSG files you can
Use Extended MAPI (C++ or Delphi only) and the OpenIMsgOnIStg function to open an MSG file. You can then create a new message in the target folder and copy properties either using IMessage.CopyTo
(keep in mind that standalone MSG files do not correctly process named properties in CopyTo
) or read the properties one at a time and set them on the target message explicitly.
Outlook Object Model can open MSG files using Application.CreateItemFromTemplate
(it will be created in an unsent state) and using Namespace.OpenSharedItem
. You can then move the message (MailItem.Move
) into the target folder
For the EML files, you can
Use Extended MAPI (C++ or Delphi only) and the built-in Outlook interface (IComverterSession). You can play with that interface in OutlookSpy (click IConverterSession button - I am its author).
Outlook Object Model does not support EML files at all. The best you can do is create your own parser and copy the EML file into Outlook one MIME header/part at a time.
If using Redemption is an option (I am its author), you can use RDOMail.Import
method - it imports MSG (olMsg
) and EML (olRfc822
) files (as well as a few other formats).
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT '//or you can call Logon
set Inbox = Session.GetDefaultFolder(olFolderInbox)
set Msg = Inbox.Items.Add
Msg.Sent = true '//since Import does not copy this property
Msg.Import("c:\temp\test.eml", 1024) ' //1024 is olRfc822
Msg.Save
Upvotes: 2