Reference a shared inbox account

…衆ロ難τιáo~ 提交于 2021-01-28 18:27:49

问题


On a shared inbox account, I would like to run a script if the email is unread.

I tried this:

Sub UnreadMail()

 Dim myEmail As Object
 Dim myNamespace As Object
 Dim myFolder As Folder

 Set myNamespace = Application.GetNamespace("MAPI")
 Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)

For Each myEmail In myFolder
 If (myEmail.UnRead) Then
  Call SaveAttachToDisk
 End If
 Next
End Sub

回答1:


You almost got it, Try using GetSharedDefaultFolder Look at MSDN GetSharedDefaultFolder Method

Option Explicit
Sub UnreadMail()
    Dim olNameSpace As Outlook.NameSpace
    Dim olShareName As Outlook.Recipient
    Dim olShareInbox As Outlook.Folder
    Dim olItem As Outlook.MailItem

    Set olNameSpace = Application.GetNamespace("MAPI")
    Set olShareName = olNameSpace.CreateRecipient("Om3r@Email.com") 'address
    Set olShareInbox = olNameSpace.GetSharedDefaultFolder(olShareName, olFolderInbox) 'Inbox


    For Each olItem In olShareInbox.Items
        If (olItem.UnRead) Then
            'Call SaveAttachToDisk
            Debug.Print olItem '// Print UnRead Item to Immediate window
        End If
    Next

End Sub


来源:https://stackoverflow.com/questions/34942467/reference-a-shared-inbox-account

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!