none
Parse email attachments for specific strings on _ItemSend Event RRS feed

  • Question

  • Pretty large order here, but alot of my research has led me down wrong roads. Basic idea is a user inserts an attachment and OnClick for the ItemSend event it parses that attachment for specific strings then Cancel=True on the ItemSend event where I would then make them choose a route. I understand the method might be different for different types of files. Any ideas?
    Monday, December 23, 2013 6:24 AM

Answers

  • Hello letsrollusafa11,

    Unfortunately the Outlook Object Model doesn't provide any method for opening attachments for editing on the fly. The regular way is to save an attachment to the disk and open it. The Attachment class provides the SaveAsFile method for saving the attachment to the specified path. Then you can use the System.IO classes for working with files on the disk. Also, if you work with open xml file formats, you can use the Open XML SDK. You can download it here. Also the Object model of the Office host applications can be used.

     Starting from Outlook 2007 the Attachment class provides the PropertyAccessor property which can be used for getting an instance of the PropertyAccessor class. It allows you to get the binary representation of your attachment (array of bytes). You just need to get the PR_ATTACH_DATA_BIN property ("http://schemas.microsoft.com/mapi/proptag/0x37010102").

    Finally, the ItemSend event is not a suitable place for long-running tasks. That is why I would recommend using the AttachmentAdd event for checking the attachment data. In the ItemSend event handler you can just check out the result of the previous operation done in the AttachmentAdd handler and saved, for example, to a user property (see the UserProperties property of the MailItem class).

    Monday, December 23, 2013 10:16 AM