Import .msg file to outlook custom folder using c#

落花浮王杯 提交于 2019-12-20 07:21:09

问题


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


回答1:


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




回答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.




回答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 (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


来源:https://stackoverflow.com/questions/40501175/import-msg-file-to-outlook-custom-folder-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!