Programmatic access to Exchange 2010 using EWS, SOAP, and Python

90 篇文章 0 订阅

Programmatic access to Exchange 2010 using EWS, SOAP, and Python

I’ve previously blogged about accessing Exchange (2007) using suds and Python. Turns out that things have changed slightly in Exchange 2010, so here’s an update.

First, you’ll need to use Alex Koshelev’s EWS-specific fork of suds, which you can grab from BitBucket. Next, you’ll need code a little like this:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import urllib2
 
from suds.client import Client
from suds.sax.element import Element
from suds.transport.http import HttpTransport
 
class Transport(HttpTransport):
     def __init__( self , * * kwargs):
         realm, uri = kwargs.pop( 'realm' ), kwargs.pop( 'uri' )
         HttpTransport.__init__( self , * * kwargs)
         self .handler = urllib2.HTTPBasicAuthHandler()
         self .handler.add_password(realm = realm,
                                   user = self .options.username,
                                   passwd = self .options.password,
                                   uri = uri)
         self .urlopener = urllib2.build_opener( self .handler)
 
transport = Transport(realm = 'nexus.ox.ac.uk' ,
                       uri = 'https://nexus.ox.ac.uk/' ,
                       username = 'abcd0123' ,
                       password = 'secret' )
                 transport = transport)
 
soap_headers = Element( 'RequestServerVersion' , ns = ns)
soap_headers.attributes.append( 'Version="Exchange2010_SP1"' )
client.set_options(soapheaders = soap_headers)
 
address = client.factory.create( 't:EmailAddress' )
address.Address = 'first.last@unit.ox.ac.uk'
 
client.service.GetUserOofSettings(address)

Differences from the previous post are:

  • Passing SOAP headers seems to be necessary in some circumstances. This post on StackOverflow came in handy in working out what to do. The MSDN documentation (e.g. this page about GetRoomLists) tells you which SOAP headers you can send.
  • Namespaces seem to be working better. We’ve created a t:EmailAddress element this time, not a ns1:EmailAddress.
  • The patch mentioned in my previous blog post has been applied, so there’s now no need to apply it yourself.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值