循环查看“已发送邮件”中的 Outlook 邮件项目文件夹
我们正在尝试访问 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该会让你继续
......
This should get you going ...
....