【发布时间】:2019-10-30 21:40:06
【问题描述】:
使用 VB.net 将邮件移动到 Outlook 中的其他文件夹时出现 Mailitem 移动错误
尝试在 VB.net 中使用 Outlook Com Interop 移动 MailItems 时,我一直在 Outlook 中遇到错误。我在访问邮件、阅读邮件或获取相关文件夹时没有任何问题,只是在尝试间歇性移动邮件时出现此错误。
这是应用程序报告的错误消息:
`System.Runtime.InteropServices.COMException(0x80040107): The operation failed. at Microsoft.Office.Interop.Outlook_Mailitem.Move(MAPIFolderDestFldr) at ApplicationName.MainWindow.EmailImport() at System.Threading....`
嗯,你明白了。
相关代码如下:
Dim OutlookAp As New Outlook.Application
Dim NS As Outlook.Namespace = OutlookAp.GetNamespace("MAPI")
Dim ObjFolder As Outlook.Folder
Dim Inbox As Outlook.Folder
Dim CEBFolder As Outlook.Folder
Dim DestinationFolder As Outlook.Folder
Dim Mesg As Outlook.Mailitem
这是我获取文件夹的方法:
For Each ObjFolder in NS.Folders
If ObjFolder.Name = "CEB Folder Name" Then
CEBFolder = ObjFolder
Exit For
End If
Next ObjFolder
编辑:包括其余文件夹:
For Each ObjFolder in CEBFolder.Folders
If ObjFolder.Name = "Inbox" then
Inbox = ObjFolder
Exit For
End If
Next ObjFolder
For Each ObjFolder in Inbox.Folders
If ObjFolder.Name = "Destination Folder" then
DestinationFolder = ObjFolder
Exit For
End If
Next ObjFolder
等等。以下是我移动消息的方式:
For Counter = Inbox.Items.Count to 1 Step -1
If TypeName(Inbox.Items(Counter)) = "MailItem" then
Mesg = Ctype(Inbox.Items(Counter), Outlook.MailItem)
'Do some parsing of the message
Mesg.Move(DestinationFolder)
End If
Next Counter
差不多就是这样。这段代码似乎大部分时间都是成功的,但 Outlook 时不时地不让我移动消息,句号。
一如既往,我们非常感谢任何想法。
【问题讨论】:
-
错误是 MAPI_E_INVALID_ENTRYID,这意味着该项目已经消失(例如,一条新消息被规则或用户移动)
标签: vb.net outlook com-interop