Pages

Tuesday, January 10, 2012

Browse through all emails in Inbox and extract the information

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

Here is the code-


Sub browse_all_emails_in_inbox_only()
'Refrence-> add-> microsoft outlook
Dim ol As Outlook.Application
Dim olns As Outlook.Namespace
Dim oinbox As Outlook.Folder
Dim oitem As Outlook.MailItem
' set outlook objects
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set oinbox = olns.GetDefaultFolder(olFolderInbox)
For Each oitem In oinbox.Items
' 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

No comments:

Post a Comment