locked
Saving attachments - Incorrect filename reported RRS feed

  • Question

  • Hi

    I'm saving attachments 99% of the time without issue.  Rather than use my code, I'll use the code supplied by MS.

    EmailToSaveAttachmentsFrom.Load()
    If EmailToSaveAttachmentsFrom.HasAttachments AndAlso TypeOf EmailToSaveAttachmentsFrom.Attachments(0) Is FileAttachment Then
    	Dim fileAttachment As FileAttachment = TryCast(EmailToSaveAttachmentsFrom.Attachments(0), FileAttachment)
    	fileAttachment.Load()
    	Console.WriteLine("FileName: " + fileAttachment.Name)
    End If

    For certain emails the file name is not reported correctly.  .FileName is equal to Nothing, so I use .Name.  The file name is MyFile.EXP, but it is being reported as <MyFile.EXP>.EXP

    If I then save the attachment it saves as MyFile.EXP.EXP

    Is the true filename held between the <>?  Why is it doing this and only on certain email attachments?

    Any help would be greatly appreciated.

    Cheers

    Thursday, July 12, 2012 3:41 PM

All replies

  • Hi,

    I have tried to repro the issue by reading the attachment details on both GetItem and GetAttachment  calls using EWSEditor (http://ewseditor.codeplex.com) on my Exchange Server 2010 SP1 and able to get value for Attachment Name as expected(e.g. ews.exp).

    Pleaes share the EWS request/response logs with us if you see different behavior when using EWSEditor.

    Regards,

    Brijs 
    Brijs Blogging... Looking Beyond the Obvious

    Thursday, July 12, 2012 10:58 PM
  • Hi


    Thanks for that, when I try to establish a connection I get: 

    Message: The request failed. The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
    Type: Microsoft.Exchange.WebServices.Data.ServiceRequestException

    Is there a way to overcome this in the EWSEditor?

    Cheers

    Edit:  OK.  I just found the Overirde SSL certificate verification option in Tools > Options
    • Edited by Ye11ow Friday, July 13, 2012 2:56 AM
    Friday, July 13, 2012 2:54 AM
  • Hi

    Not sure if the below is what you want as this is all new to me.  EWSEditor sees the name as <STKCNT.EXP>.EXP

    The log below also contains the doubled extension.

    Does that help?

    Cheers


    <Trace Tag="EwsResponse" Tid="1" Time="2012-07-13 03:25:02Z" Version="14.02.0051.000">
      <?xml version="1.0" encoding="utf-8"?>
      <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
        <s:Header>
          <h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="355" MinorBuildNumber="2" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
        </s:Header>
        <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <m:GetAttachmentResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <m:ResponseMessages>
              <m:GetAttachmentResponseMessage ResponseClass="Success">
                <m:ResponseCode>NoError</m:ResponseCode>
                <m:Attachments>
                  <t:FileAttachment>
                    <t:AttachmentId Id="AQMkADI1MmU2OGM2LTA4YTUtNDE5NC1hOTgzLWNkNjdkMzI0MjRhZgBGAAADh8DenYB5EEawTJJOytp51AcAFKerAD79REu7GTojEo2iDgAAARZTwwAAABl7kgjFJ+JIuaJKggbv5aQAAAFFXOwAAAABBgAEAAAD" />
                    <t:Name>&lt;STKCNT.EXP&gt;.EXP</t:Name>
                    <t:ContentType>application/octet-stream</t:ContentType>
                    

    Friday, July 13, 2012 3:31 AM
  • Hi,

    Please see the response as below I am getting from the test attachment file(ews.exp) which I have created as new text file and renaming it.

    We need to know how is this email with attachment getting generated.

    <Trace Tag="EwsResponse" Tid="1" Time="2012-07-12 22:50:55Z" Version="14.03.0032.000">
      <?xml version="1.0" encoding="utf-8"?>
      <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
        <s:Header>
          <h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="339" MinorBuildNumber="1" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
        </s:Header>
        <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <m:GetAttachmentResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <m:ResponseMessages>
              <m:GetAttachmentResponseMessage ResponseClass="Success">
                <m:ResponseCode>NoError</m:ResponseCode>
                <m:Attachments>
                  <t:FileAttachment>
                    <t:AttachmentId Id="AQMkADBkZjJmNDk3LTNhNzItNGQ0MC04MjdkLWYwZGJlM2I1NjExADQARgAAA9NRZeECMLVNlKunQPwFLisHAAAAdxKW47lZQIvk9ssQ5CrEAAADDwAAAXcSluO5WUCL5PbLEOQqxAAAAEWZ9FcAAAABBgAEAAAD" />
                    <t:Name>ews.exp</t:Name>
                    <t:ContentId>3f81b922-45cf-4955-9d0e-d19af9ed7f62</t:ContentId>
                    <t:Content>
                    </t:Content>
                  </t:FileAttachment>
                </m:Attachments>
              </m:GetAttachmentResponseMessage>
            </m:ResponseMessages>
          </m:GetAttachmentResponse>
        </s:Body>
      </s:Envelope>
    </Trace>

    Also, please use MFCMAPI (http://mfcmapi.codeplex.com ) to confirm the actual name of the attached file as I see  <t:Name>&lt;STKCNT.EXP&gt;.EXP</t:Name> returned by EWS.

    Follow these steps:

    • Run MFCMAPI -> Session -> Logon -> Select profile for the mailbox(where the item is saved)
    • Expand "Root - Mailbox" -> IPM_SUBTREE -> Inbox(or folder where the item is stored)
    • Double click and open the folder, select the mail item
    • Rigth click on the item and select Attachments -> "Display Attachment Table".
    • Select the attachment and check "PR_ATTACH_FILENAME".

    Please share you findings with us.

    Regards,

    Brij
    Brijs Blogging... Looking Beyond the Obvious

    Friday, July 13, 2012 3:17 PM
  • Hi

    First screenshot shows the info requested and is the correct filename.

    Second screenshot is from the display name which is incorrect.

    If you need more information let me know.

    Cheers

    Monday, July 16, 2012 2:21 AM
  • Hi,

    As requested earlier, we would like to know how is this email with attachment getting generated?

    Refer the snapshot below, for me both the properties "PR_ATTACH_FILENAME" and "PR_DISPLAY_NAME" have same value as "ews.exp"

    Regards,

    Brij
    Brijs Blogging... Looking Beyond the Obvious

    Monday, July 16, 2012 4:42 PM
  • Hi Brij

    Sorry this email is from a client, the client should not actually be sending us this email any more and we can't get in contact with them.  So I can't tell you.

    It seems only the display name is incorrect.  Can I get the FileName through the API which is correct?

    Cheers

    Tuesday, July 17, 2012 2:08 AM
  • Hi,

    Generally, We get Attachment Name and Attachment FileName as same when submitted with Outlook/OWA client.

    Unfortunately, we have hit the end of the road. As, EWS Managed API's FileAttachment.Load() won’t allow us to request additional properties.

    However, I do see that FileAttachment type exposes FileName property, which is not returning any value.

    I would suggest you to open a service request with Microsoft Support to investigate it further.

    One can open service request online @ http://support.microsoft.com/select/Default.aspx?target=assistance&sd=gn

    Regards,

    Brij
    Brijs Blogging... Looking Beyond the Obvious





    Wednesday, July 18, 2012 6:10 PM
  • Thanks for you help Brij, appreciate it.
    Sunday, July 22, 2012 9:51 AM