Hi, I am reading an xml file that contains emails with attachments (one email per item/node, but may contain multiple attachments). I am trying to save the attachments to our server. So I'm looping over the multiple attachments of a single email and using cfhttp to GET the attachments from another server and save them with the same filename on our server. The problem is that it works for the first attachment - it's saved to the server, status code is 200 OK - awesome! But for any attachments after that, it does not save them and throws a Conection Failure error. No matter what attachments they are. In trouble shooting I tried several things. First, inside of my loop of attachments, I can hardcode the cfhttp calls with the url and filename of the attachments - one right after the other - and all is perfect everytime!! But it obviously needs to be dynamic. I also tried to save a list of the attachment urls from the loop, and then call a separate cfhttp tag for each attachment in the list (so again, was in a loop) and it works for the first attachment in the list and not for the others (same errors as above). Here's a simplified version of the code. I can't put in the real xml url, and when I set the "attachmentFilename" I left out that code because it works and is too much. Please let me know if you have any suggestions, and of course, if you need more info from me!! Thanks so much, Kirsten <cfoutput> <cfhttp url="https://www.myxml.com/example.xml" method="get" resolveurl="no" /> <cfset myXML = trim(cfhttp.FileContent)> <cfset myXML = xmlParse(myXML)> <cfset theRoot = myXML.XmlRoot> <cfset numChildren = arrayLen(theRoot.XMLChildren[1].XmlChildren)> <cfloop index="i" from="6" to="#numChildren#"> <cfset attachments = theRoot.XMLChildren[1].XMLChildren[i]["attachments"].XmlText> <cfif ListLen(attachments, "|^|") gt 2> <cfset loop_unid = theRoot.XMLChildren[1].XMLChildren[i]["unid"].XmlText> <cfset counter = 0> <cfset attachmentArray = ListToArray(attachments, "|^|")> <cfloop from="1" to="#ArrayLen(attachmentArray)#" index="k"> <cfset counter = counter + 1> <cfset attachmentURL = attachmentArray[k]> <cfset attachmentFilename = Replace(attachmentArray[k],"strip the url from the filename in the url","")> <cfhttp url="#attachmentURL#" method="get" resolveurl="no" timeout="120" path="D:\my_servers_path\attachmentFolder\" file="#attachmentFilename#"> attachment counter: #counter#<BR /> cfhttp.statusCode: #cfhttp.statusCode#<BR /> cfhttp.errorDetail: #cfhttp.errorDetail#<BR /> </cfloop> </cfif> </cfloop> </cfoutput> Code (markup): Output Results for 3 attachments: attachment counter: 1 cfhttp.statusCode: 200 OK cfhttp.errorDetail: attachment counter: 2 cfhttp.statusCode: Connection Failure. Status code unavailable. cfhttp.errorDetail: I/O Exception: peer not authenticated attachment counter: 3 cfhttp.statusCode: Connection Failure. Status code unavailable. cfhttp.errorDetail: I/O Exception: peer not authenticated
Instead of doing it synchronously, try this. When you get an email, take all of the attachments that need to be retrieved and insert them into a table. Create a task that processes an item from the table. When you get an email with an attachment, schedule the processing task to run. When the processing task finishes, have it check to see if there are more items. If there are, have the task run again. If not, have it cancel the scheduled task. I use a system like that to process things via cfhttp (file uploads, downloading images), and it works well for me.
My coworker solved this! The problem was that, apparently, the list I was making of attachments had some extra spaces in it -- which didn't cause a problem for the first list item, but all others had the space, which threw the Connection Failure error. So a simple trim() around the list item inside the loop makes it work! Thanks for the reply!! YAY!!! Kirsten