循环查看“已发送邮件”中的 Outlook 邮件项目文件夹

发布于 2024-10-18 05:48:18 字数 1384 浏览 2 评论 0原文

我们正在尝试访问 Outlook 2007(使用 Exchange) 中的已发送邮件文件夹,但 TypeOf(i) 的测试为 Outlook.MailItem在下面的代码片段中始终返回 False。

我们知道我们拥有正确的文件夹,因为对 items.Count 的测试返回了正确的邮件项目数。

收件箱消息很好。如果我们将文件夹从 olFolderSentMail 更改为 olFolderInbox,则 TypeOf(i) Is Outlook.MailItem 的测试就会通过,并且很高兴向我们展示主题。

Dim app As Outlook.Application = Nothing
Dim ns As Outlook.NameSpace = Nothing
Dim siFolder As Outlook.Folder = Nothing
Dim items As Outlook.Items = Nothing

app = New Outlook.Application()
ns = app.Session


siFolder = CType(ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail), Outlook.Folder)

items = siFolder.Items

MsgBox(items.Count)

For Each i In items

    If TypeOf (i) Is Outlook.MailItem Then
        Dim mailitem As Outlook.MailItem
        mailitem = CType(i, Outlook.MailItem)
        MsgBox(mailitem.Subject)
    Else
        MsgBox("not a mailitem")
    End If
Next

更新

下面@Rob 的答案,是的,肯定有帮助。但我还是很困惑。 @Rob 的代码所做的最重要的事情是测试 .MessageClass = "IPM.Note"。如果我包含该内容,则稍后对 TypeOf x Is MailItem 的测试就会成功。如果我用 If True then 替换 @Rob 对 .MessageClass = "IPM.Note" 的测试,那么相同的代码仍然会执行,但稍后对 Is MailItem 的测试会失败。就好像仅测试 .MessageClass 就会自动将对象解析为 MailItem。

此外,已发送的项目不包含任何会议请求,因此无论如何测试似乎都是不必要的。

We're trying to access the Sent Items folder in Outlook 2007 (using Exchange) but the test for TypeOf(i) Is Outlook.MailItem in the below code snippet always returns False.

We know we have the right folder because a test for items.Count returns the correct number of mail items.

Inbox messages are fine. If we change the folder from olFolderSentMail to olFolderInbox the test for TypeOf(i) Is Outlook.MailItem passes and it's quite happy to show us the Subject.

Dim app As Outlook.Application = Nothing
Dim ns As Outlook.NameSpace = Nothing
Dim siFolder As Outlook.Folder = Nothing
Dim items As Outlook.Items = Nothing

app = New Outlook.Application()
ns = app.Session


siFolder = CType(ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail), Outlook.Folder)

items = siFolder.Items

MsgBox(items.Count)

For Each i In items

    If TypeOf (i) Is Outlook.MailItem Then
        Dim mailitem As Outlook.MailItem
        mailitem = CType(i, Outlook.MailItem)
        MsgBox(mailitem.Subject)
    Else
        MsgBox("not a mailitem")
    End If
Next

Update

@Rob's answer below, yes, definitely has helped. But I'm still puzzled. The crucial thing @Rob's code is doing is testing for .MessageClass = "IPM.Note". If I include that then the later test for TypeOf x Is MailItem succeeds. If I replace @Rob's test for .MessageClass = "IPM.Note" with If True Then then the same code still executes but the later test for Is MailItem fails. It's as if just testing for the .MessageClass automagically resolves the object into a MailItem.

Furthermore the Sent Items don't contain any meeting requests so the test would seem to be unnecessary anyway.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜访吸血鬼 2024-10-25 05:48:18

这应该会让你继续

......

Dim oSent As Outlook.MAPIFolder = oNS.GetFolderFromID(gSentEntryID, gSentStoreID)


 Dim oItems As Outlook.Items = oSent.Items

 For i as Integer = 1 To oItems.Count
   'Test to make sure item is a mail item and not a meeting request.
    If oItems.Item(i).MessageClass = "IPM.Note" Then

        If TypeOf oItems.Item(i) Is Microsoft.Office.Interop.Outlook.MailItem Then

             .....

This should get you going ...

....

Dim oSent As Outlook.MAPIFolder = oNS.GetFolderFromID(gSentEntryID, gSentStoreID)


 Dim oItems As Outlook.Items = oSent.Items

 For i as Integer = 1 To oItems.Count
   'Test to make sure item is a mail item and not a meeting request.
    If oItems.Item(i).MessageClass = "IPM.Note" Then

        If TypeOf oItems.Item(i) Is Microsoft.Office.Interop.Outlook.MailItem Then

             .....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文