代码之家  ›  专栏  ›  技术社区  ›  Vedran vranić

如何在microsoft graph中添加更多ccRecipients?

  •  0
  • Vedran vranić  · 技术社区  · 6 年前

    我正在使用Microsoft Graph连接Outlook。有人能帮我解决这个问题吗。我需要添加多个 ccRecipient bccRecipient 。我的web应用程序通过API发送、接收和读取电子邮件。但我不能发送电子邮件给多个 cc bcc 收件人这是我用来发送电子邮件的功能。

    编辑:现在函数没有两个 ccRecipients 还有两个 bccRecipients 在JSON中。我尝试了许多不同的方法,但当我在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);
                    }
                });
    
            }
    

    我需要做什么才能向多个用户发送电子邮件 ccRecipient公司 B客户 ?当我添加多个抄送收件人时,邮件总是排在最后一个。

    提前谢谢!!

    1 回复  |  直到 6 年前
        1
  •  6
  •   BrookeAH    5 年前

    我发现我可以通过以下方式格式化电子邮件地址,向多个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"
    }