How do I search email attachments

  • Thread starter Thread starter MM
  • Start date Start date
M

MM

I would like to be able to search email attachments for a given text string.
Is this possilbe or would it require a macro? If a macro is required, does
anyone have any idea where to start with this as I'm a bit stuck on how to
acheive this.
Regards,

Martin
 
Any text information within an attachment is not available using the Outlook
object model. It is available as part of a binary array of bytes in the
PR_ATTACH_DATA_BIN (property tag 0x37010102) property, but you have to use a
lower level API to get at that data and then translate it from a binary blob
into ANSI or Unicode text.

The easiest way to do what you want is to use the SaveAsFile method of the
Attachment object to save the attachment to the file system and then use
your favorite file handling methods to load the file contents as a text
stream and search in that.

Assuming the item with the attachment is open the first part of the macro
would be something like this:

Dim objItem As Object
Dim attach As Outlook.Attachment

Set objItem = Application.ActiveInspector.CurrentItem
Set attach = objItem.Attachments.Item(1) 'assuming only 1 attachment
attach.SaveAsFile "c:\foobar.txt"

If the attachment is actually text and not an image or something else that
will save it to the indicated path as "foobar.txt", which then can be opened
and read as a file and text stream.
 
You might want to upgrade to Outlook 2007, which can search across the
contents of attachments.
 
Back
Top