Import .msg file to outlook custom folder using c#

前端 未结 3 1572
孤街浪徒
孤街浪徒 2021-01-28 11:34

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

相关标签:
3条回答
  • 2021-01-28 12:13

    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 (any language) is an option, it 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
    
    0 讨论(0)
  • 2021-01-28 12:14

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

    0 讨论(0)
  • 2021-01-28 12:14

    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.

    0 讨论(0)
提交回复
热议问题