2014-03-27 39 views
2

我不確定「使用」是什麼語言,但Coldfusion等效爲什麼?將EWS代碼轉換爲Coldfusion

using Microsoft.Exchange.WebServices.Data; 
Appointment appointment = new Appointment(service); 
appointment.Subject = subject; 
appointment.Start = DateTime.Parse(StartDate); 
appointment.End = DateTime.Parse(EndDate); 
appointment.IsReminderSet = false; 
appointment.Save(); 
+0

看看在 barnyr

+0

CFexchange標記對我無效。不管怎麼說,還是要謝謝你。 – user990016

+0

我很好奇,爲什麼他們不適合你? – barnyr

回答

1

我遇到了這個問題,因爲我需要解決憑證問題與EWS API。我包含了我的Coldfusion代碼解決方案。我有這個與CF 9.1和CF工作10

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 

<html> 
    <head> 
     <title>EWS test</title> 
    </head> 

    <body> 
     <cfoutput> 
      <!--- Init the credentials and serversettings for testing---> 
      <!--- 
       The username can be any of the following formats depending on the AD settings 
       ewstest 
       [email protected] 
       ewstest\ADdomain 
     ---> 
     <cfset myUsername = "ewstest" > 
     <cfset myPassword = "*******" > 
     <!--- 
      The ADdomain must mach. It might not be the same as the e-mail domainname. 
     ---> 
     <cfset myDomain  = "ADdomain" > 
     <cfset myServer  = "owaserver" > 

     <cfset theRecipient = "[email protected]"> 

    </cfoutput> 
    <cfoutput> 
    <!--- 
       Author : Lion van Koppenhagen 
       Version : 1.5 
       Notes  : This sollution is shared by me at adobe.com at 2011-08-22 
            To allow developers to work with this sollution, Adobe included the needed libraries in Coldfusion 10.0 and up. 

       Description 
       =========== 
      With Exchange 2007 Microsoft abandoned WebDav as an interface to Exchangeserver. 
      The standard Coldfusion Tags relied on WebDav and will not work anymore. 

      Since I needed a way to interface with Exchange Server I started looking for possible solutions and this is what I came up with. 

      In december 2010 Microsoft released the Exchange Managed Services Library for java. 
      You can find it here: http://archive.msdn.microsoft.com/ewsjavaapi/Release/ProjectReleases.aspx?ReleaseId=5691 

      In the getting started document it tells you it depends on 4 3rd party libraries which you need to be download separately: 
       - Apache Commons HttpClient 3.1 (commons-httpclient-3.1.jar) 
       - Apache Commons Codec 1.4 (commons-codec-1.4.jar) 
       - Apache Commons Logging 1.1.1 (commons-codec-1.4.jar) 
       - JCIFS 1.3.15 (jcifs-1.3.15.jar) 

      With Coldfusion 9.1 (the version I tested with) you only need 
       - JCIFS 1.3.15 (jcifs-1.3.15.jar) which you can download here: http://jcifs.samba.org/src/ 

      Place the EWS Jar and the JCIFS Jar in your Coldfusion libray folder and after restarting CF server the following code should work.       

       With Coldfusion 10.0 the JCIFS jar and EWS jar are standard installed in the lib directory. 

       Additional notes 
       ================ 
       2015-05-01 
       While testing this sollution against a new customer a ran into a 401 access denied error. 
       After debugging with our client we found out the domain used to verify the credentials must match the internal AD domain. 
     ---> 
     <!--- 1. I need an instance of the ExchangeService class ---> 
     <cfobject type="Java" class="microsoft.exchange.webservices.data.ExchangeService" name="service"> 
     <cfset service.init()> 

     <!--- 2. I need to set the credentials ---> 
     <!--- 2a. Create an instance of the WebCredentials class ---> 
     <cfobject type="Java" class="microsoft.exchange.webservices.data.WebCredentials" name="credentials"> 
     <!--- 2b. Set the credentials ---> 
     <cfset credentials.init("#myUsername#","#myPassword#", "#myDomain")> 
     <!--- 2c. Set the credentials in the service object ---> 
     <cfset service.setCredentials(credentials) /> 

     <!--- 3. In need to set the URL to Exchange (stay away from autodsicovery) ---> 
     <!--- 3a. Create an instance of the Uri class ---> 
     <cfobject type="Java" class="java.net.URI" name="uri"> 
     <!--- 3b. Set the full path ---> 
     <cfset uri.init("https://#myServer#/ews/exchange.asmx")> 
     <!--- 3c. Set the url in the service object ---> 
     <cfset service.setUrl(uri) /> 

     <!--- These are the steps you need to create valid a service object. ---> 

     <!--- Now we need to do something with it. ---> 
     <!--- I create a test message to my own mailbox to see if it works ---> 
     <cfobject type="Java" action="create" class="microsoft.exchange.webservices.data.EmailMessage" name="message"> 
     <cfset message = message.init(service) /> 
     <cfset message.SetSubject("EWSTest")> 

     <cfset messageBody = CreateObject("java", "microsoft.exchange.webservices.data.MessageBody")> 
     <cfset messageBody.init("My EWS test message")> 

     <cfset message.SetBody(messageBody)> 

     <cfset message.ToRecipients.Add("#theRecipient#") > 


     #message.SendAndSaveCopy()# 
    </cfoutput> 
</body>