Office 365 C# クライアント ライブラリを使用してメールを送信しようとしています。フォルダの取得やメッセージの取得など、他の操作は正常に実行できましたが、電子メールを送信できません。
Microsoft のサンプルで提供されている MailHelper クラスを使用しています。これは方法です:
internal async Task<String> ComposeAndSendMailAsync(string subject,
string bodyContent,
string recipients)
{
// The identifier of the composed and sent message.
string newMessageId = string.Empty;
// Prepare the recipient list
var toRecipients = new List<Recipient>();
string[] splitter = { ";" };
var splitRecipientsString = recipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
foreach (string recipient in splitRecipientsString)
{
toRecipients.Add(new Recipient
{
EmailAddress = new EmailAddress
{
Address = recipient.Trim(),
Name = recipient.Trim(),
},
});
}
// Prepare the draft message.
var draft = new Message
{
Subject = subject,
Body = new ItemBody
{
ContentType = BodyType.HTML,
Content = bodyContent
},
ToRecipients = toRecipients
};
try
{
// Make sure we have a reference to the Outlook Services client.
var outlookClient = await AuthenticationHelper.GetOutlookClientAsync("Mail");
//Send the mail.
await outlookClient.Me.SendMailAsync(draft, true);
return draft.Id;
}
//Catch any exceptions related to invalid OData.
catch (Microsoft.OData.Core.ODataException ode)
{
throw new Exception("We could not send the message: " + ode.Message);
}
catch (Exception e)
{
throw new Exception("We could not send the message: " + e.Message);
}
}
私の引数は null ではなく、正しいようです。私が得ているエラーは次のとおりです。「リクエスト本文を読み取れません。」.
アプリケーションが適切なアクセス許可で登録されていることを確認したので、途方に暮れています。私のコードで何が起こっているのか誰か知っていますか?