我正在尝试使用以下代码通过Graph API向MS Teams发送消息。
Original Answer翻译成"最初的回答"
List<Recipient> recipients = new List<Recipient>();
recipients.Add(new Recipient
{
EmailAddress = new EmailAddress
{
Address = "user1@abctest.onmicrosoft.com"
}
});
// Create the message.
Message msg = new Message
{
Body = new ItemBody
{
Content = "Test message3",
ContentType = BodyType.Text,
},
ToRecipients = recipients
};
_graphServiceClient.Users["fe0bb333-3334c49-a3eb-25af61fed1db"].SendMail(msg, true).Request().PostAsync().Wait();
这段代码不能在MS Team中发送消息,而是通过电子邮件发送消息。
我正在遵循文档https://learn.microsoft.com/en-us/graph/api/message-send?view=graph-rest-1.0并尝试使用Graph Explorer发送消息,但无法正常工作。
发布:https://graph.microsoft.com/v1.0/users/fe0bb333-3335-4c49-a3eb-25af61fed1db/messages/22229b36-a7cb-4a33-a9f9-dd75742bf067/send 请求正文
但是,我从Graph Explorer获得以下错误:{ "Body": "Hello World" }
{
"error": {
"code": "ErrorInvalidIdMalformed",
"message": "Id is malformed.",
"innerError": {
"request-id": "9cddabed-f886-4c89-be8b-7b5735ad957f",
"date": "2019-04-21T05:37:11"
}
}
}