没有EWS,怎么把其他系统的Calendar同步到Exchange?(2)

本文介绍了一个使用Groovy实现的Exchange同步服务,该服务能够发送日历预约和保存任务到Exchange服务器。通过自定义参数,可以创建日程安排和任务,并进行登录验证。
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"
          ]
    }
} 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值