Reputation: 616
I am trying to develop an outlook add-in in VS 2010. It's purpose is to scan email body and attachment content for some key words and if any such words are found, email sending should be blocked. I am able to read email body and subject and to the validation but I am not understanding how to read an attachment content (txt file) while composing the mail.
attachment.GetTemporaryPath() is not giving the attachment path. I guess this works only for mails in inbox. One way I found was saving the attachment to a temp folder and reading it (attachment.saveAs()). Is this the only way to read attachment content while composing a mail ?
Possible Duplicate : C# Outlook 2007 - How do I access attachment contents directly from my addin?
But as suggested in there, I cant use Redemption. Is there any other way?
Upvotes: 4
Views: 2083
Reputation: 66215
Yes, saving the attachment data to a temporary file and reading it s the only way. In theory, you can use Attachment.PropertyAccessor.GetProperty
to read the PR_ATTACH_DATA_BIN
property, but you will run into problems for the large (> 64kB) files.
You can also use Extended MAPI to open the attachment data as IStream
(IAttach::OpenProperty(PR_ATTACH_DATA_BIN, IID_IStream)
), but it is only accessible through C++ or Delphi. You can use Redemption (any language - I am its author) that wraps Extended MAPI and exposes AsArray
and AsText
properties on both RDOAttachment and the Attachment object exposed by the Safe*Item
objects.
Upvotes: 4