To communicate with an Exchange server, you must establish a connection with the server. The connection can use the HTTP protocol or the HTTPS protocol. By default, ColdFusion connects to the mailbox that belongs to the login user name, but you can also connect to any mailbox whose owner has delegated access rights to the login user name. You can also access the server by using a proxy host.
Connections to the server can be persistent or transient:
To enable access to the Exchange server, you must ensure the following:
Ensure that IIS is configured for access to the Exchange server
To establish any connection, the Exchange server must grant the login user Outlook web access.
Enabling HTTPS access to the Exchange server
To enable HTTPS access from ColdFusion to the Exchange server you must
Enabling SSL on the Exchange server side
Use the following steps to enable SSL on the Exchange server side
As an alternative to steps 3 and 4, you could do the following: Right-click Default Web Site. In Secure Communications->Edit, check the Require secure channel (SSL) check box, click OK, and Click Apply. Select the nodes (for example Exchange) for which SSL should be enabled.
Enabling HTTPS access on the ColdFusion server
To use HTTPS to access the exchange server, you must have a valid client certificate in the JRE certificate store. You will need to install a certificate if the certificate on the Exchange server is not issued by a well known authority; The Java certificate store already contains certificates from some authorities.
You can ask your system administrator to give you a certificate that you can install on the ColdFusion server, or you can do the following:
To install the certificate, run the following command using keytool.exe, which is in the jre\bin folder:
keytool.exe -importcert -file <path_to_certificate_file> -keystore ..\lib\security\cacerts
To 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. You should 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.
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">
Transient connections last only as long as the tag that uses them takes to complete processing. To create a transient connection, you specify the connection directly in your action tag (such as cfexchangetask) by using the same attributes as you do in the cfexchangeconnection tag (with the exception of the connection name).
The following example uses a transient connection to create a single task:
<!--- Create a structure with the task fields. ---> <cfscript> stask = StructNew(); stask.Priority = "high"; stask.Status = "Not_Started"; stask.DueDate = "3:00 PM 09/14/2007"; stask.Subject = "My New Task"; stask.PercentCompleted = 0; Message = "Do this NOW!"; </cfscript> <!--- Create the task by using a transient connection. ---> <cfexchangetask action = "create" username = "#user1#" password = "#password1#" server = "#exchangeServerIP#" task = "#stask#" result = "theUID"> <!--- Display the UID to confirm that the action completed. ---> <cfdump var = "#theUID#">
In Exchange, one user can grant, or delegate, another user access rights to their account. Users can delegate reviewer (read-only), author (read-write), or editor (read-write-delete) rights to any combination of the calendar, contacts, Inbox, or task list.
To access the delegator's account as a delegated user, specify the following information:
You can do this in a cfexchangeconnection tag that opens a persistent connection, or in a ColdFusion Exchange tag that uses a transient connection.
For example, if access rights to docuser3's account are delegated to docuser4, you can use the cfexchangeconnection tag as in the following example to open a connection to docuser3's account by using docuser4's credentials:
<cfexchangeconnection action="open" connection="theConnection" server="myexchangeserver.mycompany.com" username="docuser4" password="secret" mailboxName="docuser3">
You can use this connection for any activities that docuser3 has delegated to docuser4. If docuser3, for example, has only delegated reviewer rights to the calendar, you can use this connection only with the cfexchangecalendar tag with get and getAttachments attributes.