如何将 mailItem 从一家商店移动到另一家

How can I move mailItem from 1 store to another

我正在尝试使用 Outlook 2010 和 C# 将邮件项目从 1 个商店移动到另一个商店

我已经走了很远,但不确定我是如何执行 'move' 的。我假设它是 saveas 然后 delete

我的尝试(代码大大减少)

         foreach (var mail in folder.Items)
           {
            //I am in the correct folder, and all I want to do is move all items to the 'inbox' of the store. I have already gotten the destination store and saved it as a variable called store

              Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)mail; //got the item

             mailItem.SaveAs(store.FilePath, Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG); // throws exception
             mailItem.Delete();
           }

我不确定这是否是最好的方法,但是 mailItem.SaveAs(store.FilePath, Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG); 行抛出异常:

The operation failed

除此之外我看不到更多细节

SaveAs 方法将 Microsoft Outlook 项目以指定文件类型的格式保存到指定路径。如果未指定文件类型,则使用 MSG 格式 (.msg)。因此,该方法用于将项目保存在磁盘上,而不是 Outlook 中的其他存储区。

您可以使用 MailItem class 的 Move 方法将 Microsoft Outlook 项目移动到新文件夹。例如:

Sub MoveItems() 
 Dim myNameSpace As Outlook.NameSpace 
 Dim myInbox As Outlook.Folder 
 Dim myDestFolder As Outlook.Folder 
 Dim myItems As Outlook.Items 
 Dim myItem As Object 

 Set myNameSpace = Application.GetNamespace("MAPI") 
 Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) 
 Set myItems = myInbox.Items 
 Set myDestFolder = myInbox.Folders("Personal Mail") 
 Set myItem = myItems.Find("[SenderName] = 'Eugene'") 
 While TypeName(myItem) <> "Nothing" 
  myItem.Move myDestFolder 
  Set myItem = myItems.FindNext 
 Wend 
End Sub