访问 Outlook 默认文件夹

发布于 2024-11-09 11:36:51 字数 1112 浏览 0 评论 0原文

我正在开发 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 技术交流群。

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

发布评论

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

评论(1

半衬遮猫 2024-11-16 11:36:51

您可以使用Folders 属性,并将多个Folders 属性串在一起,以获取命名空间中的任何文件夹。一些示例

Inbox(与 GetDefaultFolder(olInbox) 相同)

ns.Folders("Personal Folders").Folders("Inbox")

Inbox 的子文件夹,名为 Backup

ns.Folders("Personal Folders").Folders("Inbox").Folders("Backup")

与个人文件夹处于同一级别的 OtherInbox

ns.Folders("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))

ns.Folders("Personal Folders").Folders("Inbox")

A subfolder of Inbox named Backup

ns.Folders("Personal Folders").Folders("Inbox").Folders("Backup")

The OtherInbox at the same level as Personal Folders

ns.Folders("OtherInbox")

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.

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