Depends on how you want to go about it; will you have direct access to the mailbox or would you want to do this through the client (which it sounds like), such as Outlook?
For the later, you'll need something like vbMAPI:
Dim oOutlook As Object
Dim oOutlookNS As Object
Dim oOutlookFolder As Object
Dim oOutlookMsgs As Object
Dim oOutlookMsg As Object
Dim i As Long
Const olFolderInbox = 6
On Error GoTo Error_Handler
Set oOutlook = CreateObject("Outlook.application")
Set oOutlookNS = oOutlook.GetNamespace("MAPI")
Set oOutlookFolder = oOutlookNS.GetDefaultFolder(olFolderInbox)
Set oOutlookMsgs = oOutlookFolder.Items.Restrict("[UnRead] = True")
If oOutlookMsgs.Count = 0 Then
MsgBox "There are currently no unread e-mails."
For Each oOutlookMsg In oOutlookMsgs
i = i + 1
Debug.Print i, oOutlookMsg.Subject
On Error Resume Next
If Not oOutlookMsg Is Nothing Then Set oOutlookMsg = Nothing
If Not oOutlookMsgs Is Nothing Then Set oOutlookMsgs = Nothing
If Not oOutlookFolder Is Nothing Then Set oOutlookFolder = Nothing
If Not oOutlookNS Is Nothing Then Set oOutlookNS = Nothing
If Not oOutlook Is Nothing Then Set oOutlook = Nothing
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: UnreadEmails" & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Open in new window
IT issues often require a personalized solution. With Ask the Experts™, submit your questions to our certified professionals and receive unlimited, customized solutions that work for you.