none
Adding attachment to email trigger + getting original attachment file location RRS feed

  • Question

  • Hi,

    I was wondering whether there is a trigger when adding an attachment to an email the user is composing?  Specifically, I am wanting to somehow get the file path from where the attachment came from (not the filepath of the temp location the attachment is stored in).  I have tried googling for a trigger, but haven't found anything yet... nor have I found how to read the original file path the attachment was taken from.  Does anyone know if this is possible?

    Many thanks,

    Tom

    Wednesday, February 18, 2015 10:44 AM

Answers

  • Hello Tom,

    No, it is not.

    The Outlook object model provides the following events for the MailItem class:

    BeforeAttachmentAdd - is fired before an attachment is added to an instance of the parent object.

    AttachmentAdd - is fired when an attachment has been added to an instance of the parent object.

    But none of them provide the required information - where the attachment comes from.

    P.S. You can try to check the PathName property of the Attachment item passed as a parameter to the BeforeAttachmentAdd event handler.
    Wednesday, February 18, 2015 10:53 AM

All replies

  • Hello Tom,

    No, it is not.

    The Outlook object model provides the following events for the MailItem class:

    BeforeAttachmentAdd - is fired before an attachment is added to an instance of the parent object.

    AttachmentAdd - is fired when an attachment has been added to an instance of the parent object.

    But none of them provide the required information - where the attachment comes from.

    P.S. You can try to check the PathName property of the Attachment item passed as a parameter to the BeforeAttachmentAdd event handler.
    Wednesday, February 18, 2015 10:53 AM
  • Hi Eugene,

    Thanks for confirming my suspicions, I will check the PathName for BeforeAttachmentAdd to see if that helps.

    The reason I am wanting the path is because I want to check whether the file is part of a specific project or not, based on it being in the project designated folder... I guess an alternative is to automatically edit a tag/property of all the documents in the folder using a periodic background process, and then check the attachments for this tag/property once attached.

    Am I right in thinking that in order to read custom document properties of the attachment you need to open that file in the background, or are any custom properties readable without having to open the file (properties that I am able to set)?

    Thanks again,

    Tom

    Wednesday, February 18, 2015 11:47 AM
  • Yes, you are on the right avenue. Be aware, you need to save the attachment on disk. Also you may consider using a low-level API (Extended MAPI) which allows to get an attachment as a byte array.
    Wednesday, February 18, 2015 12:12 PM