开发者

Downloading attachments from Exchange with WebDAV

I've been trying to retrive attachment from message in Exchange 2003 server using WebDAV.

Ican successfully read messages and retrive list of attachments. However I am failing to save attachments. In both cases errors is:

"The remote server returned an error: <403> Forbidden.

Any idea what I'm doing wrong? My code:

        static void Main(string[] args)
    {

        HttpWebRequest Request;
        WebResponse Response;
        CredentialCache MyCredentialCache;
        string attachment = "http://mailserver/Exchange/Username/Inbox/Test.EML/Test.txt";
        string strUserName = "username";
        string strPassword = "password";
        string strDomain = "domain";

        try
        {
            // HttpWebRequest
            MyCredentialCache = new System.Net.CredentialCache();
            MyCredentialCache.Add(new System.Uri(attachment), "NTLM", new NetworkCredential(strUserName, strPassword, strDomain));

            Request = (HttpWebRequest)HttpWebRequest.Create(attachment);
            Request.Credentials = MyCredentialCache;
            Request.Method = "GET";
            Response = (HttpWebResponse)Request.GetResponse();
        }
        catch(Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }

        try
        {
            //开发者_如何学CWeb Client 
            string downloadPath = "D:\\Downloads";

            WebClient wcClient = new WebClient();
            wcClient.Credentials = new NetworkCredential(strUserName, strPassword, strDomain);
            string file = Path.GetFileName(attachment);
            string filename = Path.Combine(downloadPath, file);
            wcClient.DownloadFile(attachment, filename);
        }

        catch (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
        }

        Console.ReadLine();

    }


I have found solution to my problem. I created a post here showing examples: http://arturito.net/2010/03/26/c-sharp-saving-email-attachments-microsof-exchange-webdav/


Consider also use EWS Api, WebDaw not is enabled by default in Exchange 2007 servers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜