I was able to manually remove the python-ntlm library and reinstall and got
it working again.
Here is where I am now:
I ran this vbs script that sends an email via ews - and it worked. So at
least I know the exchange server is setup correctly.
Here is the vbs script:
emailaddress = "jeckersley(a)gemini.edu"
stSubjet = "hello World"
ebEmailBody = "1234567910 Blast Off"
servername = "mail.gemini.edu"
smSoapMessage = "<?xml version='1.0' encoding='utf-8'?>"
_
& "<soap:Envelope
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" "
_
& "
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" _
& "<soap:Body><CreateItem
MessageDisposition=""SendAndSaveCopy"" " _
& "
xmlns=""http://schemas.microsoft.com/exchange/services/2006/mes...
" _
& "<SavedItemFolderId><DistinguishedFolderId
Id=""sentitems""
xmlns=""http://schemas.microsoft.com/exchange/services/2006/typ...
_
& "</SavedItemFolderId><Items><Message
xmlns=""http://schemas.microsoft.com/exchange/services/2006/typ...
_
& "<ItemClass>IPM.Note</ItemClass><Subject>" &
stSubjet & "</Subject><Body
BodyType=""Text"">" & ebEmailBody &
"</Body><ToRecipients>" _
& "<Mailbox><EmailAddress>" & EmailAddress &
"</EmailAddress></Mailbox></ToRecipients></Message></Items>"
_
& "</CreateItem></soap:Body></soap:Envelope>"
set req = createobject("microsoft.xmlhttp")
req.Open "post", "https://" & servername &
"/ews/Exchange.asmx",
False,"GEMINI\jeckersley", "XXX"
req.setRequestHeader "Content-Type", "text/xml"
req.setRequestHeader "translate", "F"
req.send smSoapMessage
wscript.echo req.status
wscript.echo
wscript.echo req.responsetext
Here is the cleaned up XML from the vbs script:
<soap:Body>
<CreateItem MessageDisposition="SendAndSaveCopy"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages&...
<SavedItemFolderId>
<DistinguishedFolderId Id="sentitems"
xmlns="http://schemas.microsoft.com/exchange/services/2006/types&quo...
</SavedItemFolderId>
<Items>
<Message
xmlns="http://schemas.microsoft.com/exchange/services/2006/types&quo...
<ItemClass>IPM.Note</ItemClass>
<Subject> Hello, world </Subject>
<Body BodyType="Text">"This is a test.</Body>
<ToRecipients>
<Mailbox>
<EmailAddress>jeckersley(a)gemini.edu</EmailAddress>
</Mailbox>
</ToRecipients>
</Message>
</Items>
</CreateItem>
</soap:Body>
Then I tried to recreate this in python with suds:
import suds
from suds.client import Client
from suds.transport.https import WindowsHttpAuthenticated
# test stuff
from suds.sax.element import Element
from suds.sax.attribute import Attribute
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
url = "file:///Users/jeckersley/Sites/geminiDigest/Services.wsdl"
user = 'GEMINI\jeckersley'
password = "xxx"
ntlm = WindowsHttpAuthenticated(username=user,password=password)
c = Client(url, transport=ntlm,
location='https://mail.gemini.edu/EWS/Exchange.asmx')
createitem = Element('CreateItem')
createitem.set('MessageDisposition', 'SendAndSaveCopy')
createitem.set('xmlns','http://schemas.microsoft.com/exchange...
messages')
saveditemfolderid = Element('SavedItemFolderId')
distinguishedfolderid = Element('DistinguishedFolderId')
distinguishedfolderid.set('Id', 'sentitems')
distinguishedfolderid.set('xmlns','http://schemas.microsoft.c...
vices/2006/types')
saveditemfolderid.append(distinguishedfolderid)
createitem.append(saveditemfolderid)
items = Element('Items')
message = Element('Message')
message.set('xmlns','http://schemas.microsoft.com/exchange/se...
es')
itemclass = Element('ItemClass').setText('IPM.Note')
message.append(itemclass)
subject = Element('Subject').setText('This is a test')
message.append(subject)
body = Element('Body').setText('Hello World')
body.set('BodyType', 'Text')
message.append(body)
torecipients = Element('ToRecipients')
mailbox = Element('Mailbox')
emailaddress = Element('EmailAddress').setText('jeckersley(a)gemini.edu')
mailbox.append(emailaddress)
torecipients.append(mailbox)
message.append(torecipients)
items.append(message)
createitem.append(items)
attr = c.service.CreateItem(createitem)
Here is the xml this is generating:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<SOAP-ENV:Envelope
xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/messa...
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns0:Body>
<ns1:CreateItem>
<CreateItem MessageDisposition="SendAndSaveCopy"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages&...
<SavedItemFolderId>
<DistinguishedFolderId Id="sentitems"
xmlns="http://schemas.microsoft.com/exchange/services/2006/types&quo...
</SavedItemFolderId>
<Items>
<Message
xmlns="http://schemas.microsoft.com/exchange/services/2006/types&quo...
<ItemClass>IPM.Note</ItemClass>
<Subject>This is a test</Subject>
<Body BodyType="Text">Hello World</Body>
<ToRecipients>
<Mailbox>
<EmailAddress>jeckersley(a)gemini.edu</EmailAddress>
</Mailbox>
</ToRecipients>
</Message>
</Items>
</CreateItem>
<ns1:Items/>
</ns1:CreateItem>
</ns0:Body>
</SOAP-ENV:Envelope>
</document>
This is giving me the error: suds.WebFault: Server raised fault: 'The
request is invalid.'
Still stuck, but making a little progress.
- Jared
On 7/22/10 9:08 PM, "Erik Cederstrand" <erik(a)cederstrand.dk> wrote:
Den 22/07/2010 kl. 02.10 skrev Jared Eckersley:
> Hi,
>
> I just installed .4 and ran the demo again. This is what I am getting now:
>
> Traceback (most recent call last):
> File "demo.py", line 4, in <module>
> from Exchange import Exchange, EWSDateTime
> File "/Users/jeckersley/Sites/geminiDigest/Exchange.py", line 33, in
> <module>
> from suds.transport.https import WindowsHttpAuthenticated
> ImportError: cannot import name WindowsHttpAuthenticated
That's strange. I have a /python-suds-0.4/suds/transport/https.py file which
defines a class WindowsHttpAuthenticated(HttpAuthenticated), whic in turn
tries this:
from ntlm import HTTPNtlmAuthHandler
Can you check if that's correct in your version? If you have Suds 0.4
installed, and python is actually using it, and you have the ntlm module
installed, things should just work. Which system are you on? Can you try
deinstalling all previous Suds versions and installing just 0.4?
Thanks,
Erik