Trouble getting email attachment from Exchange
- by JimR
I am getting the error message “The remote server returned an error: (501) Not Implemented.” when I try to use the HttpWebRequest.GetResponse() using the GET Method to get an email attachment from exchange. I have tried to change the HttpVersion and don’t think it is a permissions issue since I can search the inbox.
I know my credentials are correct as they are used to get HREF using the HttpWebRequest.Method = Search on the inbox (https://mail.mailserver.com/exchange/testemailaccount/Inbox/).
HREF = https://mail.mailserver.com/exchange/testemailaccount/Inbox/testemail.EML/attachment.csv
Sample Code:
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();
}
}