如何在 Microsoft Graph 中添加更多的 ccRecipients?

How to add more ccRecipients in microsoft graph?

我正在使用 Microsoft Graph 连接 Outlook。有人可以帮我解决我的问题吗?我需要添加多个 ccRecipientbccRecipient。我的 Web 应用程序通过 API 发送、接收和阅读电子邮件。但我无法将电子邮件发送给多个 ccbcc 收件人。这是我用来发送电子邮件的功能。

编辑:目前函数在JSON中没有两个ccRecipients和两个bccRecipients。我尝试过很多不同的方法,但是当我在 Microsoft Graph-Explorer 中测试它时,它无法发送多个地址。

    function sendEmail(){

            getAccessToken(function(accessToken) {
                if (accessToken) {
// Create a Graph client
                    var client = MicrosoftGraph.Client.init({
                        authProvider: (done) => {
// Just return the token
                        done(null, accessToken);
                }
                });

                    var recipient                   = $("#recipient").val();
                    var subject                     = $("#subject").val();
                    var carbon_copies               = $("#carbon_copies").val();
                    var blind_carbon_copies         = $("#blind_carbon_copies").val();
                    var filename_attachment         = $("#filename").text();
                    var attachments_base64          = $("#attachment_base64").val();
                    var attachments_base64_replaced = attachments_base64.substring(attachments_base64.indexOf(",")+1);
                    alert(attachments_base64_replaced);



                    tinyMCE.triggerSave();
                    var body                           = $("#moj_tekst_editor").val();
                    var body_escape_double_qoute       = body.replace(/"/g, '\"');
                    //var body_escape_single_qoute       = body_escape_double_qoute.replace(/'/g, "\'");
                    var body_escape_forward_slash       = body_escape_double_qoute.replace("/", "\/");
                    var body_escape_forward_slash       = body_escape_double_qoute.replace("/", "\/");
                    alert(body_escape_forward_slash);


                    var email = '{"message":{"subject": "'+subject+'","body": {"contentType": "HTML","content": "'+body_escape_forward_slash+'"},"toRecipients": [{"emailAddress": {"address": "'+recipient+'"}}],"ccRecipients": [{"emailAddress": {"address": "'+carbon_copies+'"}}],"bccRecipients": [{"emailAddress": {"address": "'+blind_carbon_copies+'"}}],"attachments":[{"@odata.type":"#Microsoft.OutlookServices.FileAttachment","name":"'+filename_attachment+'","contentBytes":"'+attachments_base64_replaced+'"}]}, "saveToSentItems": "true"}'




                    console.log(email);



                    // Send Email
                    client
                        .api('/me/sendMail')
                        .header('Content-Type', "application/json")
                        .post(email, (err, res) => {
                        if (err) {
                            callback(null, err);
                        } else {
                            callback(res.value);
                }
                });

                } else {
                    var error = { responseText: 'Could not retrieve access token' };
                    callback(null, error);
                }
            });

        }

我需要做什么才能向多个 ccRecipientbccRecipient 发送电子邮件?当我添加多个抄送收件人时,消息总是出现在最后一个。

提前致谢!!

我发现我可以通过以下方式格式化电子邮件地址来向多个 toRecipients 或 ccRecipients 发送电子邮件:

  {
    "emailAddress": {
      "address": "cc1@email.com"
    }
  },
  {
    "emailAddress": {
      "address": "cc2@email.com"
    }
  }

完整的请求正文如下所示:

{
  "message": {
    "subject": "Meet for lunch?",
    "body": {
      "contentType": "Text",
      "content": "The new cafeteria is open."
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "address1@email.com"
        }
      },
      {
        "emailAddress": {
          "address": "address2@email.com"
        }
      }
    ],
    "ccRecipients": [
      {
        "emailAddress": {
          "address": "cc1@email.com"
        }
      },
      {
        "emailAddress": {
          "address": "cc2@email.com"
        }
      }
    ]
  },
  "saveToSentItems": "true"
}