Option Explicit
Public WithEvents sp As Items
Public olInboxFolder As MAPIFolder
Public olSpamboxFolder As MAPIFolder
'Public InboxID As String
Public SpamboxID As String
Private Sub Application_Startup()
' Deze functie wordt aangeroepen wanneer Outlook start
' Na evt. wijzigingen cursor hierin plaatsen en op F5 drukken om uit te voeren, of Outlook herstarten
' Gebruik de functie GetOutlookFolderID om onderstaande ID's te verkrijgen
' Deze verschillen per account en machine
'InboxID = "00000000F610F02F768A24409CB439CBE875E8C101004571A37BC60ED748B89AC5149E9C49270000000669AD0000"
SpamboxID = "00000000F610F02F768A24409CB439CBE875E8C1010059737BE802D4D64A95269656B96927300000074B5C050000"
'Set ns = Application.GetNamespace("MAPI").GetFolderFromID(InboxID).Items
Set sp = Application.GetNamespace("MAPI").GetFolderFromID(SpamboxID).Items
End Sub
Private Sub sp_ItemAdd(ByVal item As Object)
Dim msgItem As Object
Dim toFolder As Outlook.MAPIFolder
Set toFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
On Local Error Resume Next
For Each msgItem In sp
If msgItem.UnRead = True And item.SenderEmailAddress = "iemand@provider.com" Then
MsgBox (item.SenderEmailAddress), vbInformation
msgItem.UnRead = True
msgItem.Move toFolder
End If
Next
Set olSpamboxFolder = Nothing
End Sub