2017-03-17 2 views
0

Outlook 365 API를 사용하여 이메일에 답장을 보내려고합니다. 다음은 this tutorial입니다. 튜토리얼에 따라 우리가 입력 Commnet 필요 ReplyAll 이에 나는 그것이 Bad Request 오류를주고 그렇게 할 때 - 나는 방법을 아래에이 작업을 수행하려고Outlook 365 API에 대한 POST 요청을 ReplyAll에 보내는 방법

"error": { 
    "code": "ErrorInvalidRecipients", 
    "message": "At least one recipient isn't valid., A message can't be sent because it contains no recipients." 
} 

.

public string EmailReplyAll(AuthenticationResult result, string uriString, string msgBody) 
{ 
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uriString); 
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken); 
EmailReplyAll replyAll = new EmailReplyAll(); 
replyAll.MsgBody = msgBody; 
var jsonData = JsonConvert.SerializeObject(msgBody); 
var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); 
HttpResponseMessage response = httpClient.PostAsync(request.ToString(),content).Result; 
if (!response.IsSuccessStatusCode) 
      throw new WebException(response.StatusCode.ToString() + ": " + response.ReasonPhrase); 
uriString = response.Content.ReadAsStringAsync().Result; 
return uriString; 
} 

누군가 내가 잘못하고있는 부분을 지적 할 수 있습니까? 나는 WPF로 이것을 시도하고있다.

+0

uriString의 값은 무엇입니까? –

+0

https://outlook.office.com/api/v2.0/me/messages/{message_id}/replyall –

+0

{message_id}을 올바르게 전달하는지 확인하시기 바랍니다. 귀하의 오류는 귀하가 게시하는 message_id에서 오는 것이라고 생각되는 수신자가 누락되었음을 보여줍니다. –

답변

0

내가 알아 냈고 나를 위해 일하는 것은 여기에있다.

EmailReplyAll 클래스

public class EmailReplyAll 
{ 
    public string Comment { get; set; } 
} 

URI는 문자열 -

var uriString = String.Format(CultureInfo.InvariantCulture, "{0}api/{1}/me/messages/{2}/replyall", graphApiEndpoint, graphApiVersion, emailId); //emailId is id of email e.g - AAMkADBjMGZiZGFACAAC8Emr9AAA=

EmailReplyAll 방법 -

public string EmailReplyAll(AuthenticationResult result, string uriString, string msgBody) 
{ 
    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken); 
    EmailReplyAll replyAll = new EmailReplyAll(); 
    replyAll.Comment = msgBody; 
    var jsonData = JsonConvert.SerializeObject(replyAll); 
    var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); 
    try 
    { 
    HttpResponseMessage response = httpClient.PostAsync(uriString, content).Result; 
    var apiResult = response.Content.ReadAsStringAsync().Result; 
    } 
    catch (Exception exception) 
    { 
    return "Error"; 
    }  
    return apiResult; 
} 
관련 문제