2016-07-06 19 views
0

Outlook Mail API와 관련된 프로젝트 작업 중입니다. 이메일 첨부 파일을 다운로드하고 싶습니다. documantation은 첨부 파일을 "가져올"수 있다고 말하며 json 응답에서 다른 매개 변수를 반환하지만 실제 첨부 파일을 파일 시스템에 저장하려면 어느 파일을 변환해야하는지 궁금합니다. REST API를 사용하여 Outlook 첨부 파일을 다운로드 하시겠습니까?

http://msdn.microsoft.com/office/office365/api/mail-rest-operations#Getattachments

감사합니다. 문서 당으로

답변

2

https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments 개별 첨부 파일에 대한 식별자 포함 첨부 파일의 컬렉션을 반환 이제

{ 
    "@odata.context": "https://outlook.office.com/api/v2.0/$metadata#Me/Messages('AAMkAGI2THVSAAA%3D')/Attachments(Name)", 
    "value": [ 
     { 
      "@odata.type": "#Microsoft.OutlookServices.FileAttachment", 
      "@odata.id": "https://outlook.office.com/api/v2.0/Users('ddfcd489-628b-40d7-b48b-57[email protected]')/Messages('AAMkAGI2THVSAAA=')/Attachments('AAMkAGI2j4kShdM=')", 
      "Id": "AAMkAGI2j4kShdM=", 
      "Name": "minutes.docx" 
     } 
    ] } 

을, 당신은이 목록을 통해 반복이 API를 사용하여 개별 첨부 파일을 가져올 수 있습니다 - https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments/{attachment_id} 어디 attachment_id 위의 API에서 반환 된 식별자입니다.

응답은 다음과 같습니다

{ 
    "@odata.context": "https://outlook.office.com/api/v2.0/$metadata#Me/Messages('AAMkAGI2THVSAAA%3D')/Attachments/$entity", 
    "@odata.type": "#Microsoft.OutlookServices.FileAttachment", 
    "@odata.id": "https://outlook.office.com/api/v2.0/Users('[email protected]fad664b77')/Messages('AAMkAGI2THVSAAA=')/Attachments('AAMkAGI2j4kShdM=')", 
    "Id": "AAMkAGI2j4kShdM=", 
    "LastModifiedDateTime": "2014-10-20T00:41:52Z", 
    "Name": "minutes.docx", 
    "ContentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 
    "Size": 11585, 
    "IsInline": false, 
    "ContentId": null, 
    "ContentLocation": null, 
    "ContentBytes": "UEsDBBQABgAIAAAAIQDCAAA4KQAAAAA=" } 

지금, 당신은 ContentBytes과의 contentType을 사용하여 로컬이 첨부 파일을 저장할 수 있습니다. 또한 첨부 파일은 ItemAttachments 또는 FileAttachments 일 수 있습니다. Google에서 더 많은 정보를 검색하면 다운로드 방법을 보여주는 샘플 코드로 연결됩니다. 그러나 이것은 당신에게 아이디어를 줄 것입니다.

이 작업을 확인할 수 있습니다

public static void GetAttachmentsFromEmail(ExchangeService service, ItemId itemId) 
     { 
      // Bind to an existing message item and retrieve the attachments collection. 
      // This method results in an GetItem call to EWS. 
      EmailMessage message = EmailMessage.Bind(service, itemId, new PropertySet(ItemSchema.Attachments)); 

      // Iterate through the attachments collection and load each attachment. 
      foreach (Attachment attachment in message.Attachments) 
      { 
       if (attachment is FileAttachment) 
       { 
        FileAttachment fileAttachment = attachment as FileAttachment; 

        // Load the attachment into a file. 
        // This call results in a GetAttachment call to EWS. 
        fileAttachment.Load("C:\\temp\\" + fileAttachment.Name); 

        Console.WriteLine("File attachment name: " + fileAttachment.Name); 
       } 
       else // Attachment is an item attachment. 
       { 
        ItemAttachment itemAttachment = attachment as ItemAttachment; 

        // Load attachment into memory and write out the subject. 
        // This does not save the file like it does with a file attachment. 
        // This call results in a GetAttachment call to EWS. 
        itemAttachment.Load(); 

        Console.WriteLine("Item attachment name: " + itemAttachment.Name); 
       } 
      } 
     }