2017-03-17 11 views
0

私はOutlook 365 APIを使用して電子メールに返信しようとしています。続いてthis tutorial。私はそれがBad Requestエラーを与えていることを実行しようとするときReplyAllするチュートリアルごととして、私たちはただ入力Commnetする必要があるが -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; 
} 
関連する問題