I'm trying to write a windows service which reads some emails from Exchange
Server through WebDAV, using C#.NET 2.0 and MSXML2. Everything works fine when testing, using a little Forms application to test all the backend classes. However, when I try to run the actual service it gets an access denied message when trying to get the emails.
We have other services written in VB.NET 1.1 which use the exact same
technique, and run on the same server... and they work fine. So why would it
stop working when run as a .NET 2.0 service?
Here is the function which actually gets the email:
Code: Select all
protected XmlDataDocument GetOldestEmail(string mailbox)
{
MSXML2.ServerXMLHTTP40 server = new MSXML2.ServerXMLHTTP40();
server.open("SEARCH", mailbox, false, mUsername, mPassword);
server.setRequestHeader("Depth", "1");
server.setRequestHeader("Content-type", "text/xml");
server.setRequestHeader("Range", "Rows=0-0");
string select = "<xml>"
+ "<D>"
+ "<D>"
+ "SELECT \"DAV:href\", "
+ "\"urn:schemas:httpmail:subject\", "
+ "\"urn:schemas:httpmail:textdescription\", "
+ "\"urn:schemas:httpmail:htmldescription\", "
+ "\"urn:schemas:httpmail:datereceived\", "
+ "\"urn:schemas:httpmail:from\" "
+ "FROM scope('shallow traversal of \"" + mailbox + "\"')"
+ "WHERE \"DAV:ishidden\"=false "
+ "AND \"DAV:isfolder\"=false "
+ "ORDER BY \"urn:schemas:httpmail:datereceived\""
+ "</D></D>";
server.send(select);
XmlDataDocument dataDoc = new XmlDataDocument();
dataDoc.LoadXml(server.responseText);
return dataDoc;
}
The mailbox would be something like
https://owa.companyname.com/exchange/dispatch/IMOnsite and the
username/password are definately correct.
Any thoughts on why I'm getting Access Denied?