Search code examples
coldfusionimapcoldfusion-9

CFIMAP Reading emails from all folders


I am using CFIMAP to download email attachments daily. Despite what I have tried so far the script is reading emails from all of my folders instead from only the inbox. Anyone know how to fix this?

This is my code:

    <cfimap 
        server = "mail.example.com" 
        username = "user@sexample.com" 
        action="open" 
        secure="yes" 
        password = "pass" 
        connection = "mail.example.com" >

      <cfimap   
        action="GetAll" 
        folder="Inbox"  
        name="test"
        attachmentpath="e:\testfolder" 
        GenerateUniqueFilenames="yes"
        connection="mail.example.com" >

    <cfimap 
        action="MoveMail" 
        newfolder="processedEmails" 
        stoponerror="true" 
        connection="mail.example.com">

   <cfimap action="close" connection = "mail.example.com">

Solution

  • you can try the following code..

    <cfimap action="open" connection="Conn" server="serverurl" username="useremail"      password="passwrd" secure="yes" port="">
    <cfimap action="getall" connection="Conn" name="getAttachments" folder="Inbox" attachmentpath="#GetTempDirectory()#" >
    
    <cfquery dbtype="query" name="getMailAttachments">
        select * 
      from getAttachments 
      where seen=<cfqueryparam value="no" cfsqltype="cf_sql_varchar"> 
       and ATTACHMENTS is not null
    </cfquery>
    <cfloop query="getMailAttachments">
       <cfimap action="MarkRead" connection = "Conn" uid="#getMailAttachments.UID#">
       <cfimap action="movemail" connection = "Conn"  newfolder="Read mails" uid="#getMailAttachments.UID#">
    </cfloop>