Reading new outlook emails (1 Viewer)

EHS

Registered User.
Local time
Today, 06:47
Joined
Jun 23, 2011
Messages
22
Hi there. I want to write some script that will pick up new email message in my outlook inbox. If picking new emails can't be done, then having a script to read the emails then delete them would do. Any ideas?
Thanks
 

EHS

Registered User.
Local time
Today, 06:47
Joined
Jun 23, 2011
Messages
22
Hi there. I managed to get my code working. I hope this is useful.
Function CheckEmail2()
Dim myOutlook As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myEmail As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object

Set myOutlook = New Outlook.Application
Set myNamespace = myOutlook.GetNamespace("MAPI")
Set myEmail = myNamespace.GetDefaultFolder(olFolderInbox).Items
Set myItems = myEmail.Restrict("[Unread] = true")
For Each myItem In myItems
If (myItem.Class = olMail) Then
MsgBox "The subject is " & myItem.Subject
End If
Next
End Function

This function works if outlook is already open.
 

Users who are viewing this thread

Top Bottom