[英]MS Graph send Item type attachment not working
I'm using Microsoft graph API's but not sure how to send inline attachments ( pictures pasted in email body)
I've tried with this -
const attachment = {
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "img1.jpg",
"isInline": true,
"contentBytes": base64.replace(/^data:.+;base64,/, "")
}
const result = await client.api(`/users/${originEmail}/messages/${emailId}/attachments`).post(attachment)
then I'm updating base64 string with `cid:${result.id}` in email body
but the email which I'm receiving does not show the pictures in email and the attachment can visible as file type attachment
Also try with below code =>
{
message: {
body: {
contentType: 'html',
content: "<p class="ql-align-center"><strong style="color: rgb(23, 23, 23);">Azure App Registration</strong><span style="color: rgb(23, 23, 23);"> </span></p><p> </p><p> </p><p><strong>Step 1:- </strong> Create app registration in azure portal </p><p> </p><p><img src="cid:content0"> </p><p><strong>Step 2:-</strong> Add secret credentials </p><p><img src="cid:content1"> </p><p> </p><p><strong>Step 3:- </strong>Remove all default permissions </p><p> <img src="cid:content2"> </p><p> </p><p><strong>Step 4:-</strong> Add application permission </p><p><img src="cid:content3"> </p><p> </p><p><strong>Step 5:- </strong>Add email related permission and account level permission </p><p><strong> </strong><img src="cid:content4"> </p><p> </p><p><strong>Step 6:- </strong>Required admin consent access to approve the added permissions </p><p>Click on Grant admin consent<strong> </strong> </p><p><strong> <img src="cid:content5"> </p><p> </p><p> </p><p> </p>"
},
toRecipients: [ [Object] ],
ccRecipients: [ [Object] ],
bccRecipients: [ [Object] ],
hasAttachments: true,
subject: 'test',
attachments: [ [Object], [Object], [Object], [Object], [Object], [Object] ]
}
}
where object is
const obj ={
"@odata.type": "#microsoft.graph.fileAttachment",
"contentType":"image/png",
"contentBytes": newString.replace(/^data:.+;base64,/, ""),
"contentId":`content${i}`,
"isInline": true,
"name": `image${i}.jpg
}
在 obj 中聲明了 fileType 附件以及 Inline 標志,但仍未在 email 中獲取圖像。 如果有人知道這一點,那么將不勝感激。 提前致謝
contentId 應該與您在消息的正文中設置的內容相匹配(不是附件的 ID,例如cid:${result.id}
無效),並且應該在您創建附件時設置,例如
{ "subject": "Meet for lunch?", "body": { "contentType": "html", "content": "The new cafeteria is open. <img id='1' src='cid:blah1'>" }, "toRecipients": [ { "emailAddress": { "address": "balyh@d.com" } } ], "attachments": [ { "@odata.type": "#microsoft.graph.fileAttachment", "name": "img1.png", "isInline": true, "contentId": "blah1", "contentBytes": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFMZ/M7ubXdtdb1xSFyeilBapySVU8h8OoFaooFSqiihIVIpQBKci6KEg9Q6H9kovIHoCIVQJJCKE1ENFjnAgcaSGC6rEnxBwA04Tx43t2FnvDAfjkNibxgHxnWb2e/u992bee7tCa00YFsffekFY+nUzFtjW0LrvjRXrCDIAaPLlW0nHL0SsZtVoaF98mLrx3pdhOqLtYPHChahZcYYO7KvPFxvRl5XPp1sN3adWiD1ZAqD6XYK1b/dvE5IWryTt2udLFedwc1+9kLp+vbbpoDh+6TklxBeAi9TL0taeWpdmZzQDry0AcO+jQ12RyohqqoYoo8RDwJrU+qXkjWtfi8Xxt58BdQuwQs9qC/afLwCw8tnQbqYAPsgxE1S6F3EAIXux2oQFKm0ihMsOF71dHYx+f3NND68ghCu1YIoePPQN1pGRABkJ6Bus96CutRZMydTl+TvuiRW1m3n0eDl0vRPcEysqdXn+jsQPsrHMquGeXEaY4Yk4wxWcY5V/9scqOMOVUFthatyTy8QyqwZ+kDURKoMWxNKr2EeqVKcTNOajqKoBgOE28U4tdQl5p5bwCw7BWquaZSzAPlwjlithJtp3pTImSqQRrb2Z8PHGigD4RZuNX6JYj6wj7O4TFLbCO/Mn/m8R+h6rYSUb3ekokRY6f/YukArN979jcW+V/S8g0eT/N3VN3kTqWbQ428m9/8k0P/1aIhF36PccEl6EhOcAUCrXKZXXWS3XKd2vc/TRBG9O5ELC17MmWubD2nKhUKZa26Ba2+D3P+4/MNCFwg59oWVeYhkzgN/JDR8deKBoD7Y+ljEjGZ0sosXVTvbc6RHirr2reNy1OXd6pJsQ+gqjk8VWFYmHrwBzW/n+uMPFiRwHB2I7ih8ciHFxIkd/3Omk5tCDV1t+2nNu5sxxpDFNx+huNhVT3/zMDz8usXC3ddaHBj1GHj/As08fwTS7Kt1HBTmyN29vdwAw+/wbwLVOJ3uAD1wi/dUH7Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII=" } ] }
在后面的示例中,您將文件名設置為 jpg,但將內容類型設置為 png,並且您不應該設置 hasAttachments: true 讓商店處理它。 如果您想調試發生的事情,我建議您使用像 Outlook Spy 或 MFCMapi 這樣的 Mapi 編輯器,然后您可以在創建草稿時查看附件上設置了哪些屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.