none
Saving Outlook attachments issue RRS feed

  • Question

  • Some of our Office 2010/2013 users reported occasional duplicate attachments  in Outlook.

    On Send Mail event our COM-Addin loops through the attachment collection and copies word, excel and power-point files to the temporary folder(s), processes the files and then deletes the original office attachments and re-attaches the processed copies.

    We were finally able to reproduce the issue on  the machine with Outlook 2010 with KB3055041 applied.

    Microsoft released KB3085604 in October of the last year to address some of the issues with the attachments.

    here is the pseudo code snippet (the real code is in C++, and rather long)

    for (int i = attachments.count; i > 0; i--)

    { 

      attachments.SaveAsFile(i, tempFolder + someUniqueName;

    }

    When sending attachments A and B, intermittently, we get in the temp folder,  a two copies of file B, instead of A and B.

    This breaks the program behavior and the outgoing mail will contain a copy of A and two copies of B.

    We confirmed the issue still happens even with the latest KB update 3115127

    I wonder if anyone has any suggestions on dealing with the problem.

    Regards,

    Michael


    • Edited by Michael2015 Wednesday, June 22, 2016 7:27 PM missed character
    Wednesday, June 22, 2016 7:25 PM

All replies

  • Do you save the messages before processing the attachments?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, June 22, 2016 7:39 PM
  • Yes we do.
    Wednesday, June 22, 2016 7:47 PM
  • Hello Michael,

    What code exactly for saving, deleting and re-attaching files do you use in the ItemSend event handler?


    [custom.development]

    Wednesday, June 22, 2016 10:32 PM
  • Deleting and re-attaching files isn't issue in this case.

    The addin is written in C++, 

    the loop snippet is below

    for (int i = count; i > 0; i--)
    {
    VARIANT index;
    index.iVal = i;
    index.vt = VT_I2;
    AttachmentPtr pAttachment = _pAttachments->Item(index);
    ATLASSERT(pAttachment);
    Outlook::OlAttachmentType var = pAttachment->GetType();

    if (var == Outlook::olByValue)
    {
    if (!InspectAttachment(pAttachment, i))
    return AttachmentDefines::ResultErrors;
    }
    }

    and here is the function that save the attached file ....

    bool COutlookAttachmentHelper::CopyAttachment(AttachmentPtr& attachmentPtr)
    {
         ....
    _bstr_t _bstrNewPath(newFullPath.c_str());
    hr = attachmentPtr->SaveAsFile(_bstrNewPath);
        ....
    }

    Occasionally instead of attachments A and B I would get 2 copies of attachment B 

    If I reverse the loop I might get 2 copies of file A

    I also tried to replace the SaveAsFile call to the code that uses a Property Accessor to get the raw binary data of the attachment via PR_ATTACH_DATA_BIN schema. And I see the same issue pops up.

    Again I only see this on a machine with the Outlook patches I mentioned in the original post.

    Thank you

    Michael

    Thursday, June 23, 2016 4:12 PM
  • Hi Michael,

    >> Occasionally instead of attachments A and B I would get 2 copies of attachment B If I reverse the loop I might get 2 copies of file A

    When did you get 2 copies of B, in saving attachments or re-attaching attachments? To narrow down this issue, I would suggest you debug your code with checking below:

    1.  Check the value of newFullPath, and check whether the attachments A and B are saved correctly in the path

    In addition, I did not find how you call CopyAttachment, and how you set value for newFullPath. It would be helpful if you could share us how you call CopyAttachment and how you set value for newFullPath. I would suggest you check the saved attachments whether they are the same attachments or only their names are the same.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, June 24, 2016 3:08 AM
  • The attachment duplicate is a secondary issue and it happens due to the fact that instead of copies of A and B I get 2 copies of B in the temp folder (I rename the files when I copy them to the temp folder and keep the track of the original attachment display name).

    I have this addin in production for 5 years, the reports with this issue started coming in somewhere in the fall of 2015

    after KB3085604 patch release.

    We had  a client reporting the same issue for Outlook 2013 (couldn't reproduce the problem in our labs).

    2 weeks ago Microsoft released KB3115158. The notes (https://support.microsoft.com/en-us/kb/3115158) states

    that the update addressed 

    Attachments are rearranged, deleted, duplicated, or corrupted

    I believe that's what we still see in Outlook 2010

    Regards,

    Michael

    Friday, June 24, 2016 9:25 PM
  • Hi Michael,

    >> We were finally able to reproduce the issue on  the machine with Outlook 2010 with KB3055041 applied
    >> We confirmed the issue still happens even with the latest KB update 3115127

    Do you mean if you uninstall these two KBs, this issue would be resolved?

    >> We had  a client reporting the same issue for Outlook 2013 (couldn't reproduce the problem in our labs).

    Do you mean this issue exist on a special computer, and you could not reproduce either with Outlook 2013? Based on your description, you assume this issue is related with KB3085604, am I right? If so, I would suggest you uninstall this KB to check whether this issue is related with this KB.

    >> 2 weeks ago Microsoft released KB3115158. The notes (https://support.microsoft.com/en-us/kb/3115158) states
    If you install KB3115158, will your issue be resolved in Outlook 2013?

    To check whether this issue is related with KB or your C++ code, I suggest you make a test with below VBA code in Outlook to check whether the attachments will be saved correctly.

    Sub SaveAttachments()
        Dim mail As Outlook.MailItem
        Dim att As Outlook.Attachment
        Dim oNameSpace As Outlook.NameSpace
        Set oNameSpace = Application.GetNamespace("MAPI")
        Set mail = Application.ActiveInspector.CurrentItem ‘ double click mailItem to open Inspector window
        For Each att In mail.Attachments
            att.SaveAsFile "D:\OfficeDev\Outlook\" & att.FileName
        Next att
    End Sub

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Sunday, June 26, 2016 2:48 AM