Ved*_*nić 1 json outlook-restapi microsoft-graph-api
我正在使用 Microsoft Graph 与 Outlook 连接。有人可以帮我解决我的问题吗?我需要添加多个ccRecipient和bccRecipient。我的网络应用程序通过 API 发送、接收和读取电子邮件。但我无法向多个收件人发送cc电子邮件bcc。这是我用来发送电子邮件的功能。
编辑:现在 JSON 中的函数没有 2ccRecipients和 2 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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我需要做什么才能向多个ccRecipient和发送电子邮件bccRecipient?当我添加多个抄送收件人时,消息总是出现在最后一封邮件中。
提前致谢!!
我发现我可以通过按以下方式格式化 emailAddress 来向多个 toRecipients 或 ccRecipients 发送电子邮件:
{
"emailAddress": {
"address": "cc1@email.com"
}
},
{
"emailAddress": {
"address": "cc2@email.com"
}
}
Run Code Online (Sandbox Code Playgroud)
完整的请求正文如下所示:
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9461 次 |
| 最近记录: |