访问 Outlook 默认文件夹
我正在开发 Outlook VBA 应用程序,需要访问我的收件箱,但似乎遇到了一些问题。我正在使用 GetDefaultFoldder(olFolderInbox)
方法,但是,我设置了多个电子邮件地址,但它们都没有显示在我的个人文件夹的收件箱中。
所以我的问题是,这个默认文件夹在哪里定义的?我如何知道哪个收件箱是默认收件箱?我知道还有 GetFolderFromID
方法,如果我要使用这个方法,
我如何找到文件夹 ID 以便指向它?
这是我正在使用的代码。这是来自 Timothy Chen Allen 博客上的教程,如下所示 蒂莫西的博客。代码:
Sub find_unread()
On Error GoTo eh:
Dim ns As Outlook.NameSpace
Dim folder As MAPIFolder
Dim item As Object
Dim msg As MailItem
Set ns = Session.Application.GetNamespace("MAPI")
Set folder = ns.GetDefaultFolder(olFolderInbox)
For Each item In folder.Items
DoEvents
If (item.Class = olMail) And (item.UnRead) Then
Set msg = item
Debug.Print msg.SenderEmailAddress
msg.Display True
End If
Next
MsgBox "All messages in Inbox are read", vbInformation, "All Read"
Exit Sub
eh:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
I working on an Outlook VBA application and I need to access my inbox but I seem to be having some trouble. I am using the GetDefaultFoldder(olFolderInbox)
method, however, I have several email addresses set up and none of them show up in my personal folder's inbox.
So my question is, where is this default folder defined? How do I know which inbox is the default one? I know there is also the GetFolderFromID
method, if I were to use this,
how can I find a folders ID in order to point to it?
Here is the code I am using. This is from a tutorial on Timothy Chen Allen's blog as seen here Timothy's Blog. The code:
Sub find_unread()
On Error GoTo eh:
Dim ns As Outlook.NameSpace
Dim folder As MAPIFolder
Dim item As Object
Dim msg As MailItem
Set ns = Session.Application.GetNamespace("MAPI")
Set folder = ns.GetDefaultFolder(olFolderInbox)
For Each item In folder.Items
DoEvents
If (item.Class = olMail) And (item.UnRead) Then
Set msg = item
Debug.Print msg.SenderEmailAddress
msg.Display True
End If
Next
MsgBox "All messages in Inbox are read", vbInformation, "All Read"
Exit Sub
eh:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用Folders 属性,并将多个Folders 属性串在一起,以获取命名空间中的任何文件夹。一些示例
Inbox(与 GetDefaultFolder(olInbox) 相同)
Inbox 的子文件夹,名为 Backup
与个人文件夹处于同一级别的 OtherInbox
GetDefaultFolder 有助于快速访问默认文件夹,但如果您需要默认文件夹以外的其他文件夹,只需使用NameSpace 对象的Folders 属性在树中向下导航。
You can use the Folders property, and string multiple Folders properties together, to get at any folder in the namespace. Some examples
The Inbox (same as GetDefaultFolder(olInbox))
A subfolder of Inbox named Backup
The OtherInbox at the same level as Personal Folders
The GetDefaultFolder is good for quickly getting to a default folder, but if you need something other than the default, just navigate down the tree with the Folders property of the NameSpace object.