Modifying attachments in Outlook COM add-in?

P

Peter Woods

Hi all,

I'm developing a (managed) COM add-in for Outlook. I'd like it to be able to
intercept a user viewing or saving an attachment to a mail, and potentially
modify the attachment content so that it appears to be different.

So I've been looking at the attachment events. I can see there's quite
a range of them, but they don't give the add-in the full picture
of what's happening.

For instance, if I right-click an attachment and 'save as' then I get this
event:

ItemEvents_10_BeforeAttachmentWriteToTempFileEventHandler

But looking at the caracteristics of the arguments, I can't tell where
the user has requested the attachment to go or where the temp file is,
and many of the attachment properties are read-only.

It seems I can't modify the attachment content (there's no access
to change it from the attachment object) and can't write different
data to the temp location where it's trying to write it to, because
it doesn't tell me where that is.

Is it possible to modify an attachment at the time when it's being
referenced? Could I do it using a property accessor for the
PR_ATTACH_DATA_BIN property? Or by using the MAPIOBJECT property
and dropping into MAPI code to do the modification? Or is it deliberately
not possible?

I could potentially implement my requirement by modfiying
the attachments when I get an OnNewInspector (or inspector Activate)
in anticipation that the user might view or save them,
but that's quite an overhead.

I know this sort of thing can be done using the Exchange Client Extension
interface, but I'd prefer to develop against the COM Add-in interface
if at all possible.

Any suggestions
Peter
 
K

Ken Slovak - [MVP - Outlook]

For compatibility with the upcoming Office/Outlook 2010 I'd advise against
an ECE. They won't be supported at all in that version and are being
deprecated.

The temp file location where an attachment would be saved can be found in
the registry. Of course you'd only be able to access that file after it was
written out there and usually that happens when the attachment is being
opened directly from the Outlook item, an event you won't be able to stop or
redirect. However, you can get the temp file location,
OutlookSecureTempFolder, from
HKCU\Software\Microsoft\Office\12.0\Outlook\Security\OutlookSecureTempFolder.
That's a REG_SZ value. The "12.0" is only for Outlook 2007, for Outlook 2003
it's 11.0, etc.

The only actual access to any attachment's contents is if you save it to the
file system, detach it, then modify the file, and then reattach it.

BeforeAttachmentAdd will let you get to the attachment before it's added to
the item, but I don't think that will help since it give you no file or
object reference to what's being attached.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top