<!--- Creating a Temp Attachmetn Folder in Memory --->
<cfset sfolder = "ram://attachments" />
<cfif NOT DirectoryExists(#sfolder#) >
<cfdirectory
action="create"
directory="#sfolder#"
/>
</cfif>
<cfimap
server = "IMAP SERVER"
username = "MyUserName"
action = "open"
secure="yes"
password = "MyPassword"
connection = "imapEmail"
timeout="300" generateUniqueFilenames="Yes">
<cfimap action="GetAll" AttachmentPath ="#sfolder#" connection="imapEmail" name="AllEmails">
<cfoutput>
<!--- Looping directory files --->
<cfdirectory
name="files"
action="list"
directory="#sfolder#"
/>
<cfloop query="files">
<cffile action="copy"
destination="C:\inetpub\wwwroot\mydomain.com\wwwroot\attachments"
nameconflict="MakeUnique"
source="#sfolder#/#files.name#">
#files.name# has been downloaded. <br/>
<cffile action="delete" file="#sfolder#/#files.name#" />
</cfloop>
</cfoutput>
<cfimap action="close" connection = "imapEmail">
First, we create a folder "attachments" in Memory and then downloaded all attachment in that folder. Later, we loop through all the files in "attachments" directory and copy them to our destination folder. Simple!!
This comment has been removed by the author.
ReplyDeletewhat about a mail containing different files with same name files ,eg:if it contain a.gif,a.gif and when i use above code it only downloads first file.
ReplyDelete