Pages

Showing posts with label Browse through all Unread emails in Outlook Inbox and extract the information. Show all posts
Showing posts with label Browse through all Unread emails in Outlook Inbox and extract the information. Show all posts

Tuesday, January 10, 2012

Browse through all Unread emails in Outlook Inbox and extract the information

If you want to run a loop through all the unread emails in your outlook inbox and capture the information like subject, receive date, body,etc .

Here is the code-

Sub browse_all_unread_emails_in_inbox_only()
'tools ->Refrence ->MICROSOFT OUTLOOK
'declare outlook objects
Dim olapp As Outlook.Application
Dim olappns As Outlook.Namespace
Dim oinbox As Outlook.Folder
Dim oitem As Outlook.MailItem
'set outlook objects
Set olapp = New Outlook.Application
Set olappns = olapp.GetNamespace("MAPI")
Set oinbox = olappns.GetDefaultFolder(olFolderInbox)
If oinbox.Items.Restrict("[UnRead] = True").Count = 0 Then
MsgBox "NO Unread Email In Inbox"
Exit Sub
End If
For Each oitem In oinbox.Items.Restrict("[UnRead] = True")
' u can add if condtions to filter the emails etc.
' u can add data it to excel sheet or database table
MsgBox "Mail Subject -> " & oitem.Subject
MsgBox "Sender Email Address -> " & oitem.SenderEmailAddress
MsgBox "Sender Name -> " & oitem.SenderName
MsgBox "Mail Body -> " & oitem.Body
MsgBox "Recived Date -> " & oitem.ReceivedTime
Next
End Sub