将EWS代码转换为coldfusion

时间:2014-03-27 22:40:17

标签: c# coldfusion exchange-server exchangewebservices

我不确定用什么语言"使用"来自,但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();

1 个答案:

答案 0 :(得分: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
                ewstest@myDomain
                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 = "test@test.com">

    </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>