Skip to main content
Inspiring
November 15, 2010
Question

CFExchange and Attachment Issue

  • November 15, 2010
  • 3 replies
  • 3812 views

Hi,

I'm working on getting attachment from a message, but each time it throws 501 error message. I'm following the documentation on attachments, but the code doesnt work for me. I searched this forum as well as google. Others, having the same issue with no solution posted.

Here is the code:

    <cfif mailMessage.hasAttachment>
     <cfset i = 1>
     <cfset path = "#GetDirectoryFromPath(ExpandPath('*.*'))#attachments">
        <cfdump var="#path#\#i#">
       
        <cfloop query="mailMessage">
            <cfexchangemail action="getAttachments" connection="checkMail" folder="#session.folder#" uid="#url.id#" name="attachment"
                attachmentPath="#path#/#i#" >
           
            <cfset i++>
        </cfloop>
       
        <cfdump var="#attachment#">
    </cfif>

Any suggestions?

    This topic has been closed for replies.

    3 replies

    Inspiring
    November 15, 2010

    Here are a couple of hints from my experiences with writing an app that pulls attachments from various Exchange inboxes:

    Note that there might be multiple attachments to a message, even if OWA and Outlook show a single file, because images, logos, etc., are all attachments from Exchange's point of view.

    I do this first, to get a query that contains all of the attachment filenames

    <cfexchangemail action="getAttachments"
         connection="exchangeConnection"
         uid="#inbox.UID#"
         name="attachSummaryX">

    and then do a QofQ to remove the images, etc.

    Also, my code to pull an attachment file has a trailing backslash on the attachmentPath value:

    <cfexchangemail action="getAttachments"
               connection="exchangeConnection"
               uid="#inbox.UID#"
               name="attachInfoX"
               attachmentPath="#request.DownloadTempDirectory#\"
               generateUniqueFilenames="false">

    The above tag will load all of the message's attachments into the attachmentPath directory.

    Finally, I have found that sometimes Exchange/CFEXCHANGE lies when it says that there is an attachment (hasAttachment = Y), and in fact there is no attachment present.

    Finally, it's a good idea to put the cfexchangexxx tags inside of a TRY/CATCH because Exchange can throw oddball errors, such as claiming that the UID doesn't exist, etc.  Also always be sure when you setup a new Exchange mailbox that you want to use CFEXCHANGE with to read messages, to first log into it with OWA, otherwise you might get failures from CFEXCHANGE saying that the username/password is bad or that the server is bad.  Just part of the fun in working with CFEXCHANGE.

    -reed

    splitzerAuthor
    Inspiring
    November 16, 2010

    Adam,

    I didnt get help back when I requested for a fix, if there was one.

    Adam, Reed:

    I added the trailing slash on my attachmentPath, but it didnt seems to work. Same error message. Reed, can you post an example of:  attachmentPath="#request.DownloadTempDirectory#\"

    I might have the path wrong or something. I tried to hard code the path something like this (didnt work):

    C:\ColdFusion9\wwwroot\Exchange\attachments\1\

    This works for me:

    <cfexchangemail action="getAttachments"
         connection="exchangeConnection"
         uid="#inbox.UID#"
         name="attachSummaryX">

    However, it return the path as empty because we havent saved it. So, i'm sure the issue is related to attachmentPath...

    Inspiring
    November 16, 2010

    The request scope variable in my example is defined like the one you are using:  "C:\downloadprocessing\emailtemp" - are you certain that the account that CF server is running under has permissions to the folder you are using?  What happens if you use CF's temp folder instead, something like the customtags folder (ie, a folder that was created by the CF installer that you know for sure CF can get to)? Try running a script that has a CFFILE action="write" to put a file there - does that work (that would tell you if CF has rights to create a file in that folder).

    -reed

    Inspiring
    November 15, 2010

    What exactly happens when your code "doesn't work?"  What error do you get, and what line of code triggers the error?  Does it happen all the time, on all messages, all the time on a specific message, or is it sporadic?

    -reed

    splitzerAuthor
    Inspiring
    November 15, 2010

    I can connect to exchange server successfully, get emails etc. So,  added the above code to get attachments (when there is an attachment for an email).

    It happens on all the message that has attachments. Messages without attachment works fine.

    Exact error code:

    Exchange error Code : 501.


    Exact message

    Error performing the action.


    Line:

    24


    Line 24 is:

    <cfexchangemail action="getAttachments" connection="checkMail" folder="#session.folder#" uid="#url.id#" name="attachment"
                    attachmentPath="#path#/#i#" >

    Inspiring
    November 15, 2010

    What happens if you omit the attachmentpath attribute?

    Just trying to work out which part of this process is causing the problem?

    --

    Adam

    Inspiring
    November 15, 2010

    Do you still get the error if you make an equivalent call, but just doing an action="get"?

    And you can make the connection just fine (ie: the <cfexchangeconnection> tag is executing OK)?

    Can you make a normal HTTP connection with the credentials you are using (like via OWA).

    --

    Adam