Getting and using folder names

To get the names of folders in the mailbox, or the subfolders of a particular folder, use the cfexchangeconnection tag with the getSubfolders action. This action returns a query with a row for each subfolder. The query has three columns:

  • folder name

  • full path from the mailbox to the folder, including the Inbox

  • folder size, in bytes

You can specify the folder whose subfolders you are getting and whether to recursively get all levels of subfolders.

You can use a folder path from the getSubfolders action in the cfexchangemail tag folder attribute to specify the folder that contains the mail message that requires action. If you do not specify a folder, the cfexchangemail tag searches only the top level of the Inbox for the message on which to act.

To perform operations on mail from multiple folders, including getting mail items or attachments, you can loop over the entries in the query returned by the getSubfolders action, as the following example shows. This example generates a report of all declined meeting messages in the Inbox and all its subfolders.

<!--- Create a connection. ---> 
<cfexchangeConnection 
    action="open" 
    username ="#user2#" 
    password="#password2#" 
    server="#exchangeServerIP#" 
    connection="conn1"> 
 
<!--- Get the names and paths to all subfolders. ---> 
<cfexchangeconnection action="getSubfolders" connection="conn1" 
    name="folderInfo" folder="Inbox" recurse="yes"> 
 
<!--- Get the information from the Inbox top level.  
            The getSubfolders results do not include an Inbox row. ---> 
    <cfexchangemail action="get" connection="conn1" 
            name="theResponses"> 
        <cfexchangefilter name="MessageType" value="Meeting_Response"> 
    </cfexchangemail> 
 
<!--- Use a query of queries to select only the declined meetings. ---> 
<!--- You cannot use cfexchangefilter to filter for the meeting response type. ---> 
    <cfquery dbtype="query" name="theResponses"> 
        SELECT * FROM theResponses 
        WHERE MEETINGRESPONSE = 'Decline' 
    </cfquery> 
 
<!--- Loop through the subfolders and get the meeting responses from each 
    folder. ---> 
<cfloop query="folderInfo"> 
    <cfexchangemail action="get" connection="conn1" 
            name="#folderinfo.foldername#"> 
        <cfexchangefilter name="folder" value="#folderinfo.folderpath#"> 
        <cfexchangefilter name="MessageType" value="Meeting_Response"> 
    </cfexchangemail> 
     
    <!--- Use the evaluate function to get the name of the folder. ---> 
    <cfset meetingData=evaluate(folderinfo.foldername)> 
    <!--- Use a query of queries with a UNION clause to add this folder's  
            results to the theResponses query. ---> 
    <cfquery dbtype="query" name="theResponses"> 
        SELECT * FROM meetingData 
        WHERE MEETINGRESPONSE = 'Decline' 
        UNION 
        SELECT * FROM theResponses 
    </cfquery> 
</cfloop> 
 
<!--- Close the connection. ---> 
<cfexchangeConnection 
    action="close" 
    connection="conn1"> 
 
<!--- Display the results. ---> 
<h3>The Declined Responses:</h3> 
<cftable query="theResponses" colheaders="yes" border="yes"> 
    <cfcol header="From" text="#FROMID#"> 
    <cfcol header="Subject" text="#SUBJECT#"> 
    <cfcol header="Message" text="#MESSAGE#"> 
</cftable>