一千萬個為什麽

搜索

無法從Exchange獲取電子郵件附件

我收到錯誤消息“遠程服務器返回錯誤:(501)未實現。”當我嘗試使用GET方法從交換中獲取電子郵件附件時使用HttpWebRequest.GetResponse()。我試圖更改HttpVersion並且不認為它是權限問題,因為我可以搜索收件箱。

我知道我的憑據是正確的,因為它們用於在收件箱中使用HttpWebRequest.Method = Search來獲取HREF( https://mail.mailserver.com/exchange/testemailaccount/Inbox/ )。

HREF = https://mail.mailserver.com/exchange/testemailaccount/Inbox/testemail.EML/attachment.csv

示例代碼:

HttpWebRequest req = (System.Net.HttpWebRequest)  HttpWebRequest.CreateHREF);                
req.Method = "GET";
req.Credentials = this.mCredentialCache;
string data = string.Empty;
using (WebResponse resp = req.GetResponse())
{
    Encoding enc = Encoding.Default;
    if (resp == null)
    {
        throw new Exception("Response contains no information.");
    }

    using (StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.ASCII))
    {
        data = sr.ReadToEnd();
    }
}

最佳答案

您似乎正在使用WebDAV對Exchange 2007.默認情況下,在Exchange 2007中,未啟用WebDAV。所以你可以:

1)在Exchange 2007 Server上啟用WebDAV。

2)切換到使用Exchange Web服務。

I would recommend Option 2 since you are using C# since there is the Managed EWS API which make this kind of task much simpler than using WebDAV. It also allows you to eventually target Exchange 2010 where WebDAV has been removed completely.

轉載註明原文: 無法從Exchange獲取電子郵件附件