Coldfusion code to get multiple mail attachments using cfimap
Below given code will loop through multiple attachments of the mail and will copy the attachments to particular folder.
<cfimap action="open" connection="Conn" server="serverURL" username="useremail" password="password" secure="yes" port="portvalue">
<cfimap action="getall" connection="Conn" name="Query_getAttachments" folder="Inbox" attachmentpath="#GetTempDirectory()#" >
<cfquery dbtype="query" name="getMailAttachments">
select *
from Query_getAttachments
where seen=<cfqueryparam value="no" cfsqltype="cf_sql_varchar">
and ATTACHMENTS is not null
</cfquery>
<cfdump var="#getMailAttachments#">
<cfloop query="getMailAttachments">
<cfif getMailAttachments.ATTACHMENTS NEQ ''>
<cfloop list="#getMailAttachments.ATTACHMENTFILES#" index="singleAttachment" delimiters="#chr(9)#">
<!--- copying each files --->
<cffile action="copy" destination="destpath" source="#singleAttachment#" >
<cfset fileName_attachment = GetFileFromPath(#singleAttachment#)>
<cfset fsize="#GetFileInfo("#singleAttachment#").size#">
</cfloop>
<!--- Marking the mails as READ after reading the mail --->
<cfimap action="MarkRead" connection = "Conn" uid="#getMailAttachments.UID#">
<cfimap action="movemail" connection = "Conn" newfolder="Read mails" uid="#getMailAttachments.UID#">
</cfif>
</cfloop>
<cfimap action="close" connection = "Conn">
you can refer the following also: Coldfusion Code to get the mail attachments for unread mails using cfimap
Comments
Post a Comment