【问题标题】:Mailitem Move Error When Moving Message to a Different Folder in Outlook Using VB.net使用 VB.net 将邮件移动到 Outlook 中的不同文件夹时出现 Mailitem 移动错误
【发布时间】: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


【解决方案1】:

您似乎从未分配过DestinationFolder,因此您正尝试将消息移至Null

【讨论】:

  • 我只是省略了该代码,因为它重复了,但如果您认为它会有所帮助,我可以包含它。但是,我已经设置了目标文件夹并验证了对象正在正确加载。
  • 我已经编辑了上面的问题,以明确我正在获取所有文件夹。很抱歉造成混乱。
【解决方案2】:

您似乎无法移动 MailItems,它们是系统对未送达电子邮件等的响应。它们显示为 MailItem 类型,但似乎不支持在文件夹之间移动 - 也许它们是虚拟邮件项目。请参阅其他地方有关处理未传递消息的主题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 2014-07-26
    • 2010-12-27
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    相关资源
    最近更新 更多