我正在使用Microsoft Graph连接Outlook。有人可以帮我解决我的问题。我需要添加多个ccRecipient
和bccRecipient
。我的Web应用程序通过API发送,接收和读取电子邮件。但我无法向多个cc
和bcc
收件人发送电子邮件。这是我用来发送电子邮件的功能。
编辑:现在,函数在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);
}
});
}
如果能够向多个ccRecipient
和bccRecipient
发送电子邮件,我需要做什么?当我添加多个cc收件人邮件时,总是会收到最后一封邮件。
提前致谢!!
答案 0 :(得分:0)
我发现可以通过以下方式格式化emailAddress来将电子邮件发送给多个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"
}