ColdFusion 9.0 Resources |
Using persistent connectionsTo open a persistent connection, you use the cfexchangeconnection tag and specify the open action, the server IP address or URL, the user name, and the name of the connection (which you use in subsequent tags to specify the connection). You typically also specify a password, and can specify several other attributes, including a proxy host or a delegate mailbox ID. For details, see cfexchangeconnection in the CFML Reference. Persistent connections use HTTP or HTTPS protocol with the keepAlive property set to true. As a result, the connections do not automatically close at the end of an HTTP request or ColdFusion page. Close the connection when you are done using it. If you do not, ColdFusion retains the connection until an inactivity time-out period elapses, after which, ColdFusion recovers the connection resources. Note: You can store a connection in a persistent scope,
such as the Application scope, and reuse it on multiple pages. However,
you get no advantage by doing so, because the connections are lightweight
and you get no substantial performance gain if you use a persistent
scope.
The following example opens a connection, gets all mail sent from spamsource.com, and deletes the messages from the Exchange server: <cfexchangeConnection action = "open" username = "#user1#" password = "#password1#" server = "#exchangeServerIP#" connection = "conn1"> <cfexchangemail action = "get" name = "spamMail" connection = "conn1"> <cfexchangefilter name = "fromID" value = "spamsource.com"> </cfexchangemail> <cfloop query="spamMail"> <cfexchangemail action = "delete" connection = "conn1" uid = "#spamMail.uid#"> </cfloop> <cfexchangeConnection action = "close" connection = "conn1"> |