我一直在嘗試使用WebDAV從Exchange 2003服務器中的郵件中檢索附件。使用WebDAV從Exchange下載附件
我可以成功閱讀郵件並查看附件列表。但是我無法保存附件。在這兩種情況下,錯誤是:
「遠程服務器返回錯誤:< 403>故宮
任何想法,我做錯了 我的代碼:?
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
{
//Web 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();
}
我必須爲Exchange 2007編寫相同的應用程序,因爲上週公司更換了服務器。以下是使用Exchange Web Services執行相同操作的示例代碼: http://arturito.net/2010/06/14/c-sharp-accesing-shared-mailbox-in-exchange-web-services- 2007的Service Pack 1和的下載,附件/ – 2010-06-14 11:45:05