1

현재 소유하고있는 외부 API를 인증하는 Outlook 추가 기능을 작성하는 중입니다. 내 기능 중 하나에 대해 API 추가 기능의 첨부 파일 ID 목록을 보내고 있습니다. 그런 다음이 ID를 사용하여 Microsoft Exchange Managed API에서 해당 첨부 파일을 가져올 수 있습니다. 문제는 .NET Core를 사용하기 때문에 권장 라이브러리에 첨부 파일에 액세스하는 데 필요한 기능이 부족하다는 것입니다. 여기 ASP.NET 코어를 사용하여 Exchange Managed API에서 첨부 파일 가져 오기

내가 주 Microsoft.Exchange.WebServices 라이브러리에서 첨부 파일을 액세스 할 때 사용하는 것을 시도하고 일부 코드 :

ServiceResponseCollection<GetAttachmentResponse> getAttachmentsResponse = service.GetAttachments(attachmentInfo.attachmentIds.ToArray(), null, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent)); 

if (getAttachmentsResponse.OverallResult == ServiceResult.Success) 
{ 
    foreach (var attachmentResponse in getAttachmentsResponse) 
    { 
     // removed logic for simplicity 
    } 
} 

문제는 내가 끝에 .Result를 추가하지 않는 한 코드의 첫 번째 줄에서 오류가 발생한다는 것입니다 그것의. 이것은 .NET 코어 버전의 라이브러리 결함입니다. 내가 같이 갈 때, 작업은 결코 Awaiting Action 또는 이와 비슷한 상태를 벗어나지 않습니다.

.NET 코어 용으로 조정 된 다른 라이브러리는 Microsoft.Exchange.WebServices.NETStandard입니다. 여기

내가 그이 일을 생각한다 발견 된 일부 코드 :이 샘플로

var getAttachmentsResponse = service.GetAttachments(attachmentInfo.attachmentIds.ToArray(), null, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent)); 

foreach (var attachmentResponse in getAttachmentsResponse) 
{ 
    // removed logic for simplicity 
} 

, 객체 모델은 다르며 심지어 Overall Result는 응답에 없다. 말할 것도없이, 중복 키가 있다는 오류가 있으면 즉시 호출이 실패합니다. 이 방법은 사용자 이름/암호 자격 증명 만 수락한다는 것을 기억할 수도 있습니다.

내 API의 Outlook 이메일에서 첨부 파일을받을 수있는 다른 솔루션이 있습니까? 나는 고통스러운 명백한 것을 놓치고 있습니까?

+0

이 비동기 라이브러리처럼 보이는 ... 왜 돈 ' t 당신은 작업 결과를 얻지 못하도록 호출을 기다리고 있습니다 ... 예 var getAttachmentResponse = await service.GetAttachment (....); –

+0

앞에서 async를 추가하고 async (필요한)를 만들 때 'ServiceResponseCollection '에 'GetAwaiter'에 대한 정의가없고 'GetAwaiter'에 첫 번째 인수 유형을 허용하지 않는 오류가 표시됩니다. 'ServiceResponseCollection '을 찾을 수 있습니다 (사용 지시문 또는 어셈블리 참조가 누락 되었습니까?) – cbrawl

답변

1
또한 JSON 형식의 데이터 배열 요소로 모든 첨부 파일을 반환하는, 첨부 파일을 가져 오지하는 메시지와 일정에 대해 Outlook REST 엔드 포인트를 사용할 수 있습니다

var currentAttachments ; 
function getAttachments() 

    { 

     var options ={ 
      isRest: true, 
      asyncContext: { message: 'Hello World!' } 
      }; 

     Office.context.mailbox.getCallbackTokenAsync(options, getAttachment); 


     function getAttachment(asyncResult) 

      { 
      var token = asyncResult.value; 

      var getAttachmentsUrl = Office.context.mailbox.restUrl + 
      '/v2.0/me/messages/' + Office.context.mailbox.convertToRestId(Office.context.mailbox.item.itemId, Office.MailboxEnums.RestVersion.v2_0) + '/attachments'; 



      $.ajax({ 
      url: getAttachmentsUrl, 
      contentType: 'application/json', 
      type: 'get', 
      headers: { 'Authorization': 'Bearer ' + token } 
      }).done(function (item) { 

      currentAttachments = item; 

      }).fail(function (error) { 

      console.log(error); 

      }); 




     } 


    } 

// Then we can use Foreach Loop to iterate through these attachments 



var outputStringFromRest = ""; 
         for (i = 0; i < currentAttachments.value.length; i++) { 
          var _att = currentAttachments.value[i]; 
          outputStringFromRest += "<BR>" + i + ". Name: "; 
          outputStringFromRest += _att.Name; 
          outputStringFromRest += "<BR>ID: " + _att.Id; 
          outputStringFromRest += "<BR>contentType: " + _att.ContentType; 
          outputStringFromRest += "<BR>size: " + _att.Size; 
          outputStringFromRest += "<BR>attachmentType: " + "file"; 
          outputStringFromRest += "<BR>isInline: " + _att.IsInline; 
         } 
+0

예제에서 Rest API의 첨부 파일을 가져올 수 있습니다. 그러나 여기에서이 정보로 무엇을할까요? 이 정보를 API로 보낼 수 있고 'ContentBytes'를 사용하여 BLOB 저장소에서 실제로 첨부 파일을 보거나 만들 수 있습니까? – cbrawl

+0

예, 'base64'문자열을 원본 문서로 다시 변환하여 첨부 파일 콘텐츠를 추출하는 'base64'문자열 인 'contentBytes'를 사용할 수 있습니다. –

+0

예를 들어 알고 계십니까? 나는 본질적으로 MemoryStream을 사용하여이 원시 'contentBytes'문자열을 BLOB 저장소에 업로드하려고합니다. 그러나 문자열을 바이트 배열로 변환하여 스트림에 저장할 때마다 첨부 파일이 잘못되었거나 손상된 것으로 보입니다. – cbrawl

관련 문제