Salve a tutti!
È il mio primo post in questo forum.

Allora, io avrei bisogno che un programma sul mio PC mi legga le mail.
Io me ne intendo fino ad un certo punto di C#, quindi ho fatto una ricerca ed ho trovato del codice che metto in allegato.

codice:
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml; 
namespace Isrcomputing
{
   class ReadingMailWebDAV
   {
   public const string strServer = "Server";      // Exchange server name
      public const string strPassword = "Password";  // Account Domain Password
      public const string strDomain = "Domain";    // Domain
      public const string strAlias = "Username";  // username
      
  
      [STAThread]
      static void Main(string[] args)
      {
         System.Net.HttpWebRequest SEARCHRequest;
         System.Net.WebResponse SEARCHResponse;
         System.Net.CredentialCache MyCredentialCache;
         string strRootURI = "";
         string strQuery = "";
         byte[] bytes = null;
         System.IO.Stream SEARCHRequestStream = null;

         try
         {
            // Build the mailbox URI.
            strRootURI = "https://" + strServer + "/exchange/" + strAlias + "/Inbox/";
             MyCredentialCache = new System.Net.CredentialCache();
            MyCredentialCache.Add( new System.Uri(strRootURI),
              "NTLM",
               new System.Net.NetworkCredential(strAlias, strPassword, strDomain)
               );

            // Build the SQL query.            
    strQuery = "<?xml version=\"1.0\"?><D:searchrequest xmlns:D = \"DAV:\">"
                     + "<D:sql>SELECT \"urn:schemas:httpmail:sendername\" , \"urn:schemas:httpmail:subject\","
      + " \"urn:schemas:mailheader:from\", \"urn:schemas:httpmail:datereceived\" ,"
                     + " \"urn:schemas:httpmail:date\", \"urn:schemas:httpmail:textdescription\" ,"
                     + " \"urn:schemas:httpmail:htmldescription\", \"DAV:id\""
                     + ", \"DAV:href\""
                     + " FROM \"" + strRootURI + "\""
                     + " WHERE \"DAV:ishidden\" = false AND \"DAV:isfolder\" = false"
                     + " </D:sql></D:searchrequest>";         
            // Create a new CredentialCache object and fill it with the network
            // credentials required to access the server.
            SEARCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);
            
            ServicePointManager.ServerCertificateValidationCallback = delegate ( object sender , System.Security.Cryptography.X509Certificates.X509Certificate pCertificate , System.Security.Cryptography.X509Certificates.X509Chain pChain , System.Net.Security.SslPolicyErrors pSSLPolicyErrors ) {
    return true;
   };
            
            SEARCHRequest.Credentials = MyCredentialCache;           
            SEARCHRequest.Method = "SEARCH";    
            SEARCHRequest.ContentType = "text/xml";
            bytes = Encoding.UTF8.GetBytes((string)strQuery);          
            SEARCHRequest.ContentLength = bytes.Length;          
            SEARCHRequestStream = SEARCHRequest.GetRequestStream();            
            SEARCHRequestStream.Write(bytes, 0, bytes.Length);           
            SEARCHRequestStream.Close();
            
            SEARCHResponse = SEARCHRequest.GetResponse();
            System.Text.Encoding enc = System.Text.Encoding.Default;
   if (SEARCHResponse == null) {
     Console.WriteLine("Response returned NULL!");
   }
   Console.WriteLine(SEARCHResponse.ContentLength);
   System.IO.StreamReader sr = new System.IO.StreamReader(SEARCHResponse.GetResponseStream(),System.Text.Encoding.ASCII);
   string sa = sr.ReadToEnd();
   sr.Close();
   SEARCHResponse.Close();
  
   XmlDocument doc = new XmlDocument();
   doc.InnerXml = sa;
   XmlNodeList mailId = doc.GetElementsByTagName("a:id");
   XmlNodeList mailFrom = doc.GetElementsByTagName("e:from");
   XmlNodeList mailReceivedDate = doc.GetElementsByTagName("d:datereceived");
   XmlNodeList mailSubject = doc.GetElementsByTagName("d:subject");
   XmlNodeList mailText = doc.GetElementsByTagName("d:textdescription");
   Console.WriteLine(mailId.Count);
      
   for ( int i = 0; i < mailId.Count; ++i ) {
    Console.WriteLine("-------------------------------\n{0}: E-mail ID: {1}", i+1, mailId[i].InnerText);
    Console.WriteLine("From:\t{0}", mailFrom[i].InnerText);
    Console.WriteLine("Received:\t{0}", mailReceivedDate[i].InnerText);
    Console.WriteLine("Subject:\t{0}", mailSubject[i].InnerText);
    Console.WriteLine("Content:\n{0}", mailText[i].InnerText);
   }
 
      } catch(Exception ex) {
            // Catch any exceptions. Any error codes from the PUT
            // or MOVE method requests on the server will be caught
            // here, also.
            Console.WriteLine("Problem: {0}", ex.Message);
         }
      }
   }
}
Il problema è che quando lo avvio, mi dà errore 405.
Qualcuno può aiutarmi a trovare cosa c'è che non va?
Oppure avete altri modi per leggere le mail da un programma su un PC?

Grazie in anticipo.