英文:
Microsoft Graph SDK ErrorInvalidRecipients when sending draft email for user
问题
我正在尝试使用Microsoft Graph SDK 5.13.0为用户发送电子邮件。我收到了"ErrorInvalidRecipients"错误消息 - "至少有一个收件人无效。不能发送消息,因为它不包含任何收件人。"
这是我的代码:
var graphMessage = new Message
{
Subject = "Test",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "Test"
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "***@***.com"
}
}
}
};
// 创建草稿以添加大附件
var draftMessage = await client.Users["no-reply@***.com"].Messages.PostAsync(graphMessage);
// 附件将添加到 draftMessage
var body = new SendMailPostRequestBody
{
Message = draftMessage
};
// 产生"ErrorInvalidRecipients"错误代码
await client.Users["no-reply@***.com"].SendMail.PostAsync(body);
希望这有助于你解决问题。
英文:
I am trying to send an email for a user using Microsoft Graph SDK 5.13.0. I am receiving "ErrorInvalidRecipients" - "At least one recipient is not valid., A message can't be sent because it contains no recipients".
Here's my code:
var graphMessage = new Message
{
Subject = "Test",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "Test"
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "***@***.com"
}
}
}
};
// Create draft to be able to add large attachments
var draftMessage = await client.Users["no-reply@***.com"].Messages.PostAsync(graphMessage);
// Attachments would be added to draftMessage
var body = new SendMailPostRequestBody
{
Message = draftMessage
};
// Produces "ErrorInvalidRecipients" error code
await client.Users["no-reply@***.com"].SendMail.PostAsync(body);
答案1
得分: 0
I didn't find anything in the documentation that mentions this yet but it turns out the error was a result of using:
我在文档中没有找到提到这一点的内容,但事实证明错误是由于使用以下方式引起的:
await client.Users["no-reply@***.com"].SendMail.PostAsync(body);
正确的方法是使用:
await client.Users["no-reply@***.com"].Messages[body.Message.Id].Send.PostAsync();
Since I was trying to send a draft message, SendMail
was not working correctly (or wasn't designed for drafts). SendMail
works correctly if I don't create drafts.
由于我尝试发送一封草稿邮件,SendMail
并没有正常工作(或者并不适用于草稿)。如果我不创建草稿,SendMail
就可以正常工作。
英文:
I didn't find anything in the documentation that mentions this yet but it turns out the error was a result of using:
await client.Users["no-reply@***.com"].SendMail.PostAsync(body);
The correct way is to use:
await client.Users["no-reply@***.com"].Messages[body.Message.Id].Send.PostAsync();
Since I was trying to send a draft message, SendMail
was not working correctly (or wasn't designed for drafts). SendMail
works correctly if I don't create drafts.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论