循环浏览“已发送邮件"中的Outlook邮件项目;文件夹 [英] Looping over Outlook mail items in "Sent Items" folder

查看:112
本文介绍了循环浏览“已发送邮件"中的Outlook邮件项目;文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

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

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

更新

@Rob在下面的回答,是的,肯定有帮助.但是我还是很困惑. @Rob的代码所做的关键是测试.MessageClass = "IPM.Note".如果我将其包括在内,则以后对TypeOf x Is MailItem的测试将成功.如果我用If True Then替换@Rob对.MessageClass = "IPM.Note"的测试,则仍然执行相同的代码,但以后对Is MailItem的测试失败.就像只是测试.MessageClass一样,它会自动将对象解析为MailItem.

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.

推荐答案

这应该可以帮助您...

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

             .....

这篇关于循环浏览“已发送邮件"中的Outlook邮件项目;文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆