我使用 microsoft graph 的服务来发送带有附件的电子邮件。但是当我发送邮件时,它没有我设置的附件。这是我生成的 Json
` message: {
attachments: attachments[],
subject: Email.Subject,
body: {
contentType: "HTML",
content: Email.body
},
toRecipients: [
{
emailAddress: {
address: Email.To
}
}
],
},
saveToSentItems: true
}
这是我的附件数组
0: {@odata.type: "#microsoft.graph.fileAttachment", contentBytes: "iVBORw0KGgoAAAANSUhEUgAAAPwA…JkiRJkiRJkiRJkiQZ4f8B1nomcWdNLuoAAAAASUVORK5CYII=", name: "outbound.png"}
1: {@odata.type: "#microsoft.graph.fileAttachment", contentBytes: "iVBORw0KGgoAAAANSUhEUgAAAQAA…eGOdrvC6af95tuTmRRrb4fxZWJvYuBoVJAAAAAElFTkSuQmCC", name: "inbound.png"}
`
这是我使用发送邮件的api的方式
sendMail: async function(accessToken, email) {
const client = getAuthenticatedClient(accessToken);
const sentResult = await client.api('/users/{tenantid}/sendMail').post(email);
}
问题是,电子邮件已发送,但为什么没有附件
这就是我阅读文件的方式
var attachments = [];
function addAttachments() {
allFiles.forEach(a => {
let reader = new FileReader();
reader.readAsDataURL(a);
reader.onload = function() {
attachments.push({
'@odata.type': "#microsoft.graph.fileAttachment",
name: a.name,
contentType: a.type,
contentBytes: reader.result.split(',')[1],
});
};
})}
这里是电子邮件 email_object对象的控制台日志
这是我对对象进行字符串化时的结果
{"message":{"subject":"[AU1588259832480]-random subject","body":{"contentType":"HTML","content":"<p>body test</p>"},"toRecipients":[{"emailAddress":{"address":"email@test.com"}}],"internetMessageId":"AU1588259832480","attachments":[]}}
attachmen 对象是空的,但为什么呢?