json MSPraphAPI-调用-RestMethod-发送邮件-多个收件人

j13ufse2  于 2022-12-20  发布在  其他
关注(0)|答案(1)|浏览(141)

我正在使用MS Graph API sendMail,我想添加超过1个用户作为收件人。与2个用户它的工作,但不知道如何添加超过2人。
我的Invoke-RestMethod代码是:

$BodyJsonsend = @"
                    {
                        "message": {
                            "subject": "$($Subject)",
                            "body": {
                                "contentType": "HTML",
                                "content": "$($Body)"
                            },
                            "toRecipients": [
                                {
                                    "emailAddress": {
                                        "address": "mail1@domain.com"
                                    }
                                }
                            ],
                            "ccRecipients": [
                                {
                                    "emailAddress": {
                                    "address": "mail2@domain.com"
                                    }
                                },
                                {
                                    "emailAddress": {
                                    "address": "mail3@domain.com"
                                    }
                                }
                            ]
                        },
                        "saveToSentItems": "true"
                    }
"@

有没有人能告诉我,JSON应该是什么样子的?上面的JSON不起作用。
我还尝试了以下json

"ccRecipients": [
    {
        "emailAddress": {
        "address": "mail2@domain.com"
        },
        "emailAddress": {
        "address": "mail3@domain.com"
        }
    }
]
yhived7q

yhived7q1#

我的Invoke-Restmethod调用是:

Invoke-RestMethod -Method POST -Uri $URLsend -Headers $headers -Body $BodyJsonsend

网址为

https://graph.microsoft.com/v1.0/users/sender@domain.com/sendMail

我没有收到错误信息。响应是202接受。我通过Postman触发了Post,它在那里工作。所以正确的代码是:

$BodyJsonsend = @"
                    {
                        "message": {
                            "subject": "$($Subject)",
                            "body": {
                                "contentType": "HTML",
                                "content": "$($Body)"
                            },
                            "toRecipients": [
                                {
                                    "emailAddress": {
                                        "address": "mail1@domain.com"
                                    }
                                }
                            ],
                            "ccRecipients": [
                                {
                                    "emailAddress": {
                                    "address": "mail2@domain.com"
                                    }
                                },
                                {
                                    "emailAddress": {
                                    "address": "mail3@domain.com"
                                    }
                                }
                            ]
                        },
                        "saveToSentItems": "true"
                    }
"@

昨天它不起作用...谢谢你的支持。

相关问题