anu katari Ответов: 0

Экспорт письма как .эмл/.формат музыкальных файлов с помощью веб-служб Exchange


Я последовал предложению от этот и смог генерировать успешные результаты отклика. Тем не менее, я до сих пор найти его трудно получить полную почту, как .файл EML/MSG от этого ответа.

Можно ли получить полную почту в виде файла вместо вложений ?.

Что я уже пробовал:

Как получить рекуррентные данные из JavaScript API в office365 - Stack Overflow[^]

HttpWebRequest webRequest = WebRequest.CreateHttp(request.ewsUrl);
webRequest.Headers.Add("Authorization", string.Format("Bearer {0}", request.attachmentToken));
webRequest.PreAuthenticate = true;
webRequest.AllowAutoRedirect = false;
webRequest.Method = "POST";
webRequest.ContentType = "text/xml; charset=utf-8";

// Construct the SOAP message for the GetAttchment operation.
// byte[] bodyBytes = Encoding.UTF8.GetBytes(string.Format(GetAttachmentSoapRequest, attachment.id));
byte[] itemBytes = Encoding.UTF8.GetBytes(string.Format(GetItemSoapRequest, request.ItemId, request.ChangeKey));
webRequest.ContentLength = itemBytes.Length;

Stream requestStream = webRequest.GetRequestStream();
requestStream.Write(itemBytes, 0, itemBytes.Length);
requestStream.Close();

// Make the request to the Exchange server and get the response.
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

// If the response is okay, create an XML document from the
// response and process the request.
if (webResponse.StatusCode == HttpStatusCode.OK)
{
    Stream responseStream = webResponse.GetResponseStream();
    //using (StreamReader reader = new StreamReader(responseStream))
    //{
    //    var filePath = string.Format("F:\\data\\Mail{0}.eml", DateTime.Now.Ticks.ToString());
    //    // use whatever method you want to save the data to the file...
    //    File.AppendAllText(filePath, webResponse.Headers.ToString());
    //    File.AppendAllText(filePath, reader.ReadToEnd());
    //}
    var responseEnvelope = XElement.Load(responseStream);
    // After creating a memory stream containing the contents of the
    // attachment, this method writes the XML document to the trace output.
    // Your service would perform it's processing here.
    if (responseEnvelope != null)
    {
        var processResult = ProcessXmlResponse(responseEnvelope);
        //attachmentNames.Add(string.Format("{0} {1}", attachment.name, processResult));

    }


    //XmlDocument xmlDocument = new XmlDocument();
    //xmlDocument.Load(responseStream);
    //var path = string.Format("F:\\data\\Mail{0}.xml", DateTime.Now.Ticks.ToString());
    //xmlDocument.Save("F:\\data\\testMail1.xml");
    // This method simply writes the XML document to the
    // trace output. Your service would perform its
    // processing here.
    //Trace.Write(xmlDocument.InnerXml);

    // Close the response stream.
    responseStream.Close();
    webResponse.Close();
}



вот мыльный запрос

 private const string GetItemSoapRequest =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"">
<soap:Header>
<t:RequestServerVersion Version=""Exchange2013"" />
</soap:Header>
  <soap:Body>
    <GetItem
      xmlns=""http://schemas.microsoft.com/exchange/services/2006/messages""
      xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"">
      <ItemShape>
        <t:BaseShape>Default</t:BaseShape>
        <t:IncludeMimeContent>true</t:IncludeMimeContent>
      </ItemShape>
      <ItemIds>
        <t:ItemId Id = ""{0}"" ChangeKey=""{1}"" />
      </ItemIds>
    </GetItem>
  </soap:Body>
</soap:Envelope>";

0 Ответов