'Import .msg file to outlook custom folder using c#

I need to add the .msg files to outlook custom folder using VSTO addin c#



Solution 1:[1]

Outlook.Application objOutlook = new Outlook.Application(); Outlook.MailItem email = (Outlook.MailItem)objOutlook.Session.OpenSharedItem(strFilePath); Outlook.MailItem movedItem = email.Move(ParentFolder);

Solution 2:[2]

You can open an existing Outlook message from a disk by using the CreateItemFromTemplate method of the Application class. The method creates a new Microsoft Outlook item from an Outlook template (.oft) and returns the new item. But you can pass an Outlook .msg file too. The How To: Create a new Outlook message based on a template article explains all the steps in details.

Another way is to run the .msg file programmatically. The Process.Start method can be used for that, you just need to specify the file path. The message will be opened in the running Outlook instance due to the fact that Outlook is a singleton. So, you can handle the NewInspector event and get a handle to the message just opened.

Solution 3:[3]

CreateItemFromTemplate creates new items in the unsent state.

If you want messages in the sent state, you can use either Extended MAPI (C++ or Delphi) to open the MSG file (OpenIMsgOnIStg etc.) and copy the properties into the message created in the folder (keep in mind that IMessage::CopyTo won't work since MSG files do not remap named properties correctly which can result in a corrupted message).

If using Redemption (I am its author - any language) is an option, its RDOMail object allows to set the Sent property before the message is saved for the very first time (MAPI limitation) and import an MSG file using the Import method (MSG is one of supported formats):

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  set Folder = Session.GetFolderFromID(YourOutlookFolder.EntryID)
  set Item = Folder.Items.Add("IPM.Note")
  Item.Sent = true
  Item.Import "c:\temp\test.msg", olMsg
  Item.Save

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chiku sharma
Solution 2 Eugene Astafiev
Solution 3