問題描述
通過 Office 加載項將內容添加到 Outlook 電子郵件正文 (Adding content to an Outlook email body via an Office Add‑In)
我創建了一個 Office 加載項,並希望將一些 html 內容添加到電子郵件正文中。這可行,但內容有所改變,因此我的 css 無法正常工作。出於某種原因,添加“x_”作為屬性的前綴(見圖)
我正在使用Office.mailbox.item.body.setSelectedDataAsync 方法添加 html。
您可以在 GitHub 上找到代碼:https://github.com/genevangampelaere/OutlookTrelloAddIn
參考解法
方法 1:
I don't know why it's adding the x_ prefix, but the main problem is that you are setting css styles, not classes, and that should be in a style
attribute not a class
attribute.
Office.context.mailbox.item.body.setSelectedDataAsync("<div style=\"border‑left‑width: 2px;border‑left‑color: #0067A3;border‑left‑style: solid;padding‑left: 10px;\"><h2>" + card.name + "</h2><div>" + card.desc + "</div></div>", { coercionType: Office.CoercionType.Html });
方法 2:
Here is the answer from Microsoft in their add‑in documentation (https://dev.office.com/reference/add‑ins/outlook/1.5/Body).
"When working with HTML‑formatted bodies, it is important to note that the Body.getAsync and Body.setAsync methods are not idempotent. The value returned from the getAsync method will not necessarily be exactly the same as the value that was passed in the setAsync method previously. The client may modify the value passed to setAsync in order to make it render efficiently with its rendering engine."
(by Gene Vangampelaere、lgaud、Violaman)