import groovyx.net.http.*
class ExchangeSyncService {
static transactional = true
static DOMAIN = 'my-domain'
static CTMS_SYNC_USERNAME = 'usr'
static CTMS_SYNC_PASSWORD = 'pwd'
static HTTP_BUILDER_POOL = [:]
private static getHttpBuilder(username) {
HTTP_BUILDER_POOL[username] ?: ( HTTP_BUILDER_POOL[username] = new HTTPBuilder( "https://webmail.${DOMAIN}.com" ) )
}
def sendAppointment(params) {
def username = CTMS_SYNC_USERNAME, password = CTMS_SYNC_PASSWORD
_login(username, password)
getHttpBuilder(username).post( path: "/Exchange/${username}/日历", body: getAppointmentBody(params)) {res->
println res.statusLine.statusCode
}
}
def saveTask(params) {
def username = params.session.user?.username, password = params.session.user?.password
_login(username, password)
getHttpBuilder(username).post( path: "/Exchange/${username}/任务", body: getTaskBody(params)) {res->
println res.statusLine.statusCode
}
}
private _login(username, password) {
getHttpBuilder(username).post(
path: '/exchweb/bin/auth/owaauth.dll',
body: [destination:"https://webmail.${DOMAIN}.com/Exchange",
flags:'0',
username:"${DOMAIN}/${username}",
password:password]
) {res->
if( res.statusLine.statusCode == 302 ) {
println "${username} logged in to exchange server successfully."
}
}
}
private getAppointmentBody(m) {
[
"Cmd": "sendappt",
"CmdReferring": "new",
"Embedded": "0",
"FORMTYPE": "appointment",
"Importance": "2",
"Optional": m.optional,//"sam.ds.chen@gmail.com; somebody@grs-cro.com",
"ReadForm": "1",
"Required": m.required,//"sachen@grs-cro.com",
"Resource": m.resource,//"sam.ds.chen@hotmail.com",
"urn:schemas:calendar:alldayevent": "1",
"urn:schemas:calendar:busystatus": "BUSY",
"urn:schemas:calendar:dtend": m.dtend,//"2011-09-21T16:00:00.000Z", //bug:总是用Exchange服务器所在的美国时区
"urn:schemas:calendar:dtstart": m.dtstart,//"2011-09-21T15:30:00.000Z", //bug:总是用Exchange服务器所在的美国时区
"urn:schemas:calendar:location": "",
"urn:schemas:calendar:reminderoffset": m.reminderoffset,//"900",
"urn:schemas:calendar:responserequested": "0",
"urn:schemas:httpmail:importance": "1",
"urn:schemas:httpmail:subject": m.subject,//"(sent by ctmssync)",
"urn:schemas:httpmail:textdescription": "Accept it to get it on your calendar"
]
}
private getTaskBody(m) {
[
"Cmd": "savetask",
"CmdReferring": "new",
"Embedded": "0",
"FORMTYPE": "task",
"MsgClass": "IPM.Task",
"ReadForm": "1",
"SENDUPDATE": "0",
"exception": "",
"http://schemas.microsoft.com/exchange/tasks/percentcomplete": "0",
"http://schemas.microsoft.com/exchange/tasks/resetreminder": "",
"http://schemas.microsoft.com/mapi/reminderset": "1",
"task_due": m.task_due,//"2011-08-04T00:00:00.000Z",
"task_remindertime": m.remindertime,//"2011-10-06T08:00:00.000Z",
"task_start": m.task_start,//"2011-10-04T00:00:00.000Z",
"task_status": "0",
"urn:schemas:httpmail:importance": "1",
"urn:schemas:httpmail:subject": m.subject,//"Title_2",
"urn:schemas:httpmail:textdescription": "This is a task created by SmartCTMS on behalf of you"
]
}
}
没有EWS,怎么把其他系统的Calendar同步到Exchange?(2)
最新推荐文章于 2023-01-15 10:25:34 发布
本文介绍了一个使用Groovy实现的Exchange同步服务,该服务能够发送日历预约和保存任务到Exchange服务器。通过自定义参数,可以创建日程安排和任务,并进行登录验证。

711

被折叠的 条评论
为什么被折叠?



