Exchange EWS Coldfusion-需要将WebDav转换为EWS [英] Exchange EWS Coldfusion - need to convert WebDav to EWS

查看:100
本文介绍了Exchange EWS Coldfusion-需要将WebDav转换为EWS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法通过EWS连接到我的交换服务器并发送电子邮件.我需要一个如何创建日历项目的示例.

I've managed to connect to my exchange server via EWS and send an email. I need an example of how to create a calendar item.

冷融合9 Exchange 2007

Coldfusion 9 Exchange 2007

<cfobject type="Java" class="microsoft.exchange.webservices.data.ExchangeService" name="service">
<cfobject type="Java" class="microsoft.exchange.webservices.data.ExchangeVersion" name="version">
<cfset service.init(version.Exchange2007_SP1)>
<cfobject type="Java" class="microsoft.exchange.webservices.data.WebCredentials" name="credentials">
<cfset credentials.init("z@x.com","password")>
<cfset service.setCredentials(credentials) />
<cfobject type="Java" class="java.net.URI" name="uri">
<cfset uri.init("server URL")>
<cfset service.setUrl(uri) />
<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 again")>
<cfset message.SetBody( messageBody )>
<cfset message.ToRecipients.Add("email@gmail.com") >
<cfset message.SendAndSaveCopy() >

我尝试了以下代码,但只得到一个只显示"Subject"的错误;

I tried the following code but only got an error that only says "Subject";

<cfobject type="Java" class="microsoft.exchange.webservices.data.ExchangeService" name="appointment">
<cfset appointment.Subject = "Dentist Appointment">
<cfset appointment.Body = "The appointment is with Dr. Smith.">
<cfset appointment.Start = createDateTime(Year('2014/03/22'), Month('2014/03/22'), 
 Day('2014/03/22'), Hour('09:00'), Minute('09:00'), 0)>
<cfset appointment.End = createDateTime(Year('2014/03/22'), Month('2014/03/22'), 
 Day('2014/03/22'), Hour('09:00'), Minute('09:00'), 0)>
<cfset appointment.Save(SendInvitationsMode.SendToNone)>

(编辑)-当前代码:

    <cfset StartDateTime = createDateTime(Year('2014/03/22'), Month('2014/03/22'), Day('2014/03/22'), Hour('09:00'), Minute('09:00'), 0)>
<cfset EndDateTime = createDateTime(Year('2014/03/22'), Month('2014/03/22'), Day('2014/03/22'), Hour('09:30'), Minute('09:30'), 0)>
<cfscript>
    exchangeService = createObject("java", "microsoft.exchange.webservices.data.ExchangeService");
    exchangeVersion = createObject("java", "microsoft.exchange.webservices.data.ExchangeVersion");
    service = exchangeService.init(exchangeVersion.Exchange2007_SP1);
    webCredentials = createObject("java", "microsoft.exchange.webservices.data.WebCredentials");
    service.setCredentials(webCredentials.init("z@x.com","password"));
    serviceURI = createObject("java", "java.net.URI").init("https://owa016.msoutlookonline.net/EWS/Exchange.asmx?wsdl"));
    service.setUrl(serviceURI);
    appointment = createObject("java", "microsoft.exchange.webservices.data.Appointment").init(service);
    appointment.Start = "#StartDateTime#";
appointment.End = "#EndDateTime#";
    appointment.Subject = "Dentist Appointment";
    appointment.Body = "The appointment is with Dr. Smith.";
    appointment.Save(SendInvitationsMode.SendToNone);
</cfscript> 

(编辑2)-部分解决方案;

(edit 2) - partial solution;

<cfset StartDateTime = createDateTime(Year('2014/03/22'), Month('2014/03/22'), Day('2014/03/22'), Hour('09:00'), Minute('09:00'), 0)>
<cfset EndDateTime = createDateTime(Year('2014/03/22'), Month('2014/03/22'), Day('2014/03/22'), Hour('09:30'), Minute('09:30'), 0)>
<!--- <cfoutput>Start=#StartDateTime#<br>End=#EndDateTime#</cfoutput><cfabort> --->
<cfscript>
    exchangeService = createObject("java", "microsoft.exchange.webservices.data.ExchangeService");
    exchangeVersion = createObject("java", "microsoft.exchange.webservices.data.ExchangeVersion");
    service = exchangeService.init(exchangeVersion.Exchange2007_SP1);
    webCredentials = createObject("java", "microsoft.exchange.webservices.data.WebCredentials");
    service.setCredentials(webCredentials.init("z@x.com","password"));
    serviceURI = createObject("java", "java.net.URI").init("https://owa016.msoutlookonline.net/EWS/Exchange.asmx?wsdl");
    service.setUrl(serviceURI);
    appointment = createObject("java", "microsoft.exchange.webservices.data.Appointment").init(service);
    appointment.setStartTimeZone(microsoft.exchange.webservices.data.TimeZoneDefinition)
    appointment.setStart("#StartDateTime#");
    appointment.setEnd("#EndDateTime#");
    appointment.setSubject("Dentist Appointment");
    MessageBody = createObject("java", "microsoft.exchange.webservices.data.MessageBody");
    appointment.setBody( MessageBody.init("The appointment is with Dr. Smith.") );
    SendInvitationsMode = createObject("java", "microsoft.exchange.webservices.data.SendInvitationsMode");
    appointment.Save(SendInvitationsMode.SendToNone);
</cfscript> 

这是我得到的错误; 设置Start,End,IsAllDayEvent或Recurrence属性时需要StartTimeZone.您必须加载或分配此属性,然后再尝试更新约会.

This is the error I got; StartTimeZone required when setting the Start, End, IsAllDayEvent, or Recurrence properties. You must load or assign this property before attempting to update the appointment.

这听起来像Exchange 2010,而我正在使用Exchange 2007.

That sounds like Exchange 2010 and I'm on Exchange 2007.

推荐答案

(评论太长了……)

尽管不是完整的答案,但有关代码的一些观察结果:

Though not a complete answer, a few observations about the code:

  • 使用Java对象时,真正的错误通常包含在堆栈跟踪中,而不是错误标头中.还要始终检查堆栈跟踪.在这种情况下,它会报告

  • When working with java objects, the true error is often contained in the stack trace, rather than the error header. Always check the stack trace too. In this case it reports

java.lang.NoSuchFieldException: SUBJECT at coldfusion.runtime.StructBean.bindName(StructBean.java:243)


  • 该错误的最可能原因是您使用了错误的对象类型.您尝试设置的属性在ExchangeService类中不存在.我相信您需要创建一个Appointment对象的实例,它确实具有subject,startdate等属性.类似于此 C#示例中显示的内容.

  • The most likely reason for that error is that you are using the wrong type of object. The properties you are attempting to set do not exist in the ExchangeService class. I believe you need to create an instance of an Appointment object instead, which does have the subject, startdate, etcetera properties. Similar to what is shown in this C# example.

(请注意,我个人更喜欢使用cfscript作为Java代码,因为语法非常相似.以您的原始示例为基础,类似以下内容:)

(Side note, personally I prefer cfscript for java code as the syntax is very similar. Using your original example as a base, something along these lines:)

exchangeService = createObject("java", "microsoft.exchange.webservices.data.ExchangeService");
exchangeVersion = createObject("java", "microsoft.exchange.webservices.data.ExchangeVersion");
service = exchangeService.init(exchangeVersion.Exchange2007_SP1);

webCredentials = createObject("java", "microsoft.exchange.webservices.data.WebCredentials");
service.setCredentials(webCredentials.init("z@x.com","password") );

serviceURI = createObject("java", "java.net.URI").init("server URL");
service.setUrl(serviceURI);

appointment = createObject("java", "microsoft.exchange.webservices.data.Appointment").init(service);
// ... set subject, date, etcetera properties 





如果您使用C#示例作为基础,请记住语法并不总是完全翻译.从理论上讲,CF支持使用以下语法直接分配属性,但前提是:

If you are using C# examples as a base, keep in mind the syntax does not always translate exactly. In theory, CF supports direct assignment of properties using the syntax below, but only if "[the] class conforms to the JavaBeans pattern.":

<cfset appointment.Subject = "Dentist Appointment">

EWS类可能不是这种情况.您可能需要显式调用方法:

That may not be case with the EWS classes. You may need to invoke the methods explicitly:

<cfset appointment.setSubject("Dentist Appointment")>

不是简单的字符串.您需要创建microsoft.exchange.webservices.data.MessageBody的实例.

The "Body" property is not a simple string. You need to create an instance of microsoft.exchange.webservices.data.MessageBody instead.

SendInvitationsMode也是一个类.您需要先创建一个实例,然后才能在此处使用其属性:

SendInvitationsMode is also a class. You need to create an instance of it before you can use its properties here:

appointment.Save(SendInvitationsMode.SendToNone);

这篇关于Exchange EWS Coldfusion-需要将WebDav转换为EWS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆