Extracting info from an Outlook email

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to automatically extract the body of an incoming email and export the
result to a database or spreadsheet. Similar functions are available through
tools such as Mailbag Assistant for Outlook Express and other email programs.
Is there a way to do this with Microsoft Outlook?
 
Outlook (unlike Outlook Express) has a rich programming model allowing automation from its own VBA environment, as well as outside applications. You'd use the MailItem.Body property to return the message body.
 
Hello,

Here's some sample code I use in Excel to play around with email
properties. You could easily adapt this to do what you want.


Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olInbox As Outlook.MAPIFolder
Dim Item As Outlook.MailItem

Set olApp = GetObject(, "outlook.application")
Set olNS = olApp.GetNamespace("MAPI")
Set olInbox = olns.GetDefaultFolder(olFolderInbox)

If olInbox.UnReadItemCount > 0 Then
For Each Item In olInbox.Items.Restrict("[Unread] = True")
MsgBox olInbox.UnReadItemCount & "unread emails"
Msgbox "To: " & Item.To
Msgbox "From: " & Item.SenderName
Msgbox "Subject: " & Item.Subject
Msgbox "Body: " & Item.body
Next Item
Else
MsgBox "No new/unread emails", vbInformation
End If

'destroy
Set olInbox = Nothing
Set olNS = Nothing
Set olApp = Nothing


HTH,
JP
 
Back
Top