gpt4 book ai didi

c# - 将 EWS 代码转换为冷融合

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:00 27 4
gpt4 key购买 nike

我不确定“using”来自什么语言,但 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();

最佳答案

我遇到这个问题是因为我需要解决 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>

关于c# - 将 EWS 代码转换为冷融合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22700736/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com