Ricevere email da win service (ms exchange)

venerdì 27 marzo 2009 - 10.41

050782 Profilo | Junior Member

Sto sviluppando un win service che dovrebbe essere in grado di scaricare la posta ricevuta su un server exchange.
Ho cercato anche l'impossibile online e fatto decine di prove, ma non ce n'è uno che va... qualcuno ha mai sviluppato qualcosa di simile?

questo è il mio codice (che ho preso dal sito MSDN)
Dim Request As System.Net.HttpWebRequest Dim Response As System.Net.HttpWebResponse Dim MyCredentialCache As System.Net.CredentialCache Dim strPassword As String Dim strDomain As String Dim strUserName As String Dim strRootURI As String Dim strQuery As String Dim bytes() As Byte Dim RequestStream As System.IO.Stream Dim ResponseStream As System.IO.Stream Dim ResponseXmlDoc As System.Xml.XmlDocument Dim DisplayNameNodes As System.Xml.XmlNodeList Try strUserName = "userName" strPassword = "userpwd" strDomain = "userDomain" strRootURI = "http://miourl/" strQuery = "<?xml version=""1.0""?>" & _ "<D:searchrequest xmlns:D = ""DAV:"" >" & _ "<D:sql>SELECT ""DAV:displayname"" FROM """ & strRootURI & """" & _ "WHERE ""DAV:ishidden"" = false AND ""DAV:isfolder"" = false" & _ "</D:sql></D:searchrequest>" MyCredentialCache = New System.Net.CredentialCache MyCredentialCache.Add(New System.Uri(strRootURI), _ "NTLM", _ New System.Net.NetworkCredential(strUserName, strPassword, strDomain) _ ) Request = CType(System.Net.WebRequest.Create(strRootURI), _ System.Net.HttpWebRequest) Request.Credentials = MyCredentialCache Request.Method = "SEARCH" bytes = System.Text.Encoding.UTF8.GetBytes(strQuery) Request.ContentLength = bytes.Length RequestStream = Request.GetRequestStream() RequestStream.Write(bytes, 0, bytes.Length) RequestStream.Close() Request.ContentType = "text/xml" Request.Headers.Add("Translate", "F") Response = CType(Request.GetResponse(), System.Net.HttpWebResponse) ResponseStream = Response.GetResponseStream() ResponseXmlDoc = New System.Xml.XmlDocument ResponseXmlDoc.Load(ResponseStream) DisplayNameNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname") If DisplayNameNodes.Count > 0 Then Console.WriteLine("Non-folder item display names...") Dim i As Integer For i = 0 To DisplayNameNodes.Count - 1 Console.WriteLine(DisplayNameNodes(i).InnerText) Next Else Console.WriteLine("No non-folder items found...") End If ResponseStream.Close() Response.Close() Catch ex As Exception Console.WriteLine(ex.Message) End Try

l'errore che mi ritorna è: "Errore del server remoto: (401) Non autorizzato."
dipende forse dalle credenziali?
nel mio app.config cmq ho impostato
<system.net> <defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy> </system.net>


UPDATE: alla fine sono riuscita a leggere i messaggi tramite webdav, ma ho comunque optato per un'altra soluzione... comprare un bel componente che con poche righe di codice ti gestisce tutto e non ho problemi di autorizzazioni!!
Lascio il link del sito, magari a qualcuno può interessare ;-)
http://www.independentsoft.de/index.html
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5