|
9588 | 9588 | https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/20-item-body/add-inline-base64-image.yaml
|
9589 | 9589 |
|
9590 | 9590 |
|
9591 |
| - const mailItem = Office.context.mailbox.item; |
| 9591 | + // Get the current body of the message or appointment. |
9592 | 9592 |
|
9593 |
| - const base64String = |
9594 |
| - "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAnUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN0S+bUAAAAMdFJOUwAQIDBAUI+fr7/P7yEupu8AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAF8SURBVGhD7dfLdoMwDEVR6Cspzf9/b20QYOthS5Zn0Z2kVdY6O2WULrFYLBaLxd5ur4mDZD14b8ogWS/dtxV+dmx9ysA2QUj9TQRWv5D7HyKwuIW9n0vc8tkpHP0W4BOg3wQ8wtlvA+PC1e8Ao8Ld7wFjQtHvAiNC2e8DdqHqKwCrUPc1gE1AfRVgEXBfB+gF0lcCWoH2tYBOYPpqQCNwfT3QF9i+AegJfN8CtAWhbwJagtS3AbIg9o2AJMh9M5C+SVGBvx6zAfmT0r+Bv8JMwP4kyFPir+cswF5KL3WLv14zAFBCLf56Tw9cparFX4upgaJUtPhrOS1QlY5W+vWTXrGgBFB/b72ev3/0igUdQPppP/nfowfKUUEFcP207y/yxKmgAYQ+PywoAFOfCH3A2MdCFzD3kdADBvq10AGG+pXQBgb7pdAEhvuF0AIc/VtoAK7+JciAs38KIuDugyAC/v4hiMCE/i7IwLRBsh68N2WQjMVisVgs9i5bln8LGScNcCrONQAAAABJRU5ErkJggg=="; |
| 9593 | + Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, |
| 9594 | + (bodyResult) => { |
| 9595 | + if (bodyResult.status === Office.AsyncResultStatus.Failed) { |
| 9596 | + console.log(`Failed to get body: ${bodyResult.error.message}`); |
| 9597 | + return; |
| 9598 | + } |
9595 | 9599 |
|
9596 |
| - // Get the current body of the message or appointment. |
| 9600 | + // Add the Base64-encoded image to the end of the body. |
| 9601 | + const options = { isInline: true, asyncContext: bodyResult.value }; |
| 9602 | + Office.context.mailbox.item.addFileAttachmentFromBase64Async(base64String, "sample.png", options, (attachResult) => { |
| 9603 | + if (attachResult.status === Office.AsyncResultStatus.Failed) { |
| 9604 | + console.log(`Failed to attach file: ${attachResult.error.message}`); |
| 9605 | + return; |
| 9606 | + } |
9597 | 9607 |
|
9598 |
| - mailItem.body.getAsync(Office.CoercionType.Html, (bodyResult) => { |
9599 |
| - if (bodyResult.status === Office.AsyncResultStatus.Succeeded) { |
9600 |
| - // Insert the Base64-encoded image to the beginning of the body. |
9601 |
| - const options = { isInline: true, asyncContext: bodyResult.value }; |
9602 |
| - mailItem.addFileAttachmentFromBase64Async(base64String, "sample.png", options, (attachResult) => { |
9603 |
| - if (attachResult.status === Office.AsyncResultStatus.Succeeded) { |
9604 |
| - let body = attachResult.asyncContext; |
9605 |
| - body = body.replace("<p class=MsoNormal>", `<p class=MsoNormal><img src="cid:sample.png">`); |
9606 |
| - |
9607 |
| - mailItem.body.setAsync(body, { coercionType: Office.CoercionType.Html }, (setResult) => { |
9608 |
| - if (setResult.status === Office.AsyncResultStatus.Succeeded) { |
9609 |
| - console.log("Inline Base64-encoded image added to the body."); |
9610 |
| - } else { |
9611 |
| - console.log(setResult.error.message); |
9612 |
| - } |
9613 |
| - }); |
9614 |
| - } else { |
9615 |
| - console.log(attachResult.error.message); |
| 9608 | + let body = attachResult.asyncContext; |
| 9609 | + body += '<img src="cid:sample.png" />'; |
| 9610 | + |
| 9611 | + Office.context.mailbox.item.body.setAsync(body, { coercionType: Office.CoercionType.Html }, (setResult) => { |
| 9612 | + if (setResult.status === Office.AsyncResultStatus.Failed) { |
| 9613 | + console.log(`Failed to set body: ${setResult.error.message}`); |
| 9614 | + return; |
9616 | 9615 | }
|
| 9616 | + |
| 9617 | + console.log("Inline Base64-encoded image added to the end of the body."); |
9617 | 9618 | });
|
9618 |
| - } else { |
9619 |
| - console.log(bodyResult.error.message); |
9620 |
| - } |
| 9619 | + }); |
9621 | 9620 | });
|
9622 | 9621 | 'Office.Body#appendOnSendAsync:member(1)':
|
9623 | 9622 | - >-
|
|
9656 | 9655 | https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/20-item-body/add-inline-base64-image.yaml
|
9657 | 9656 |
|
9658 | 9657 |
|
9659 |
| - const mailItem = Office.context.mailbox.item; |
| 9658 | + // Get the current body of the message or appointment. |
9660 | 9659 |
|
9661 |
| - const base64String = |
9662 |
| - "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAnUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN0S+bUAAAAMdFJOUwAQIDBAUI+fr7/P7yEupu8AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAF8SURBVGhD7dfLdoMwDEVR6Cspzf9/b20QYOthS5Zn0Z2kVdY6O2WULrFYLBaLxd5ur4mDZD14b8ogWS/dtxV+dmx9ysA2QUj9TQRWv5D7HyKwuIW9n0vc8tkpHP0W4BOg3wQ8wtlvA+PC1e8Ao8Ld7wFjQtHvAiNC2e8DdqHqKwCrUPc1gE1AfRVgEXBfB+gF0lcCWoH2tYBOYPpqQCNwfT3QF9i+AegJfN8CtAWhbwJagtS3AbIg9o2AJMh9M5C+SVGBvx6zAfmT0r+Bv8JMwP4kyFPir+cswF5KL3WLv14zAFBCLf56Tw9cparFX4upgaJUtPhrOS1QlY5W+vWTXrGgBFB/b72ev3/0igUdQPppP/nfowfKUUEFcP207y/yxKmgAYQ+PywoAFOfCH3A2MdCFzD3kdADBvq10AGG+pXQBgb7pdAEhvuF0AIc/VtoAK7+JciAs38KIuDugyAC/v4hiMCE/i7IwLRBsh68N2WQjMVisVgs9i5bln8LGScNcCrONQAAAABJRU5ErkJggg=="; |
| 9660 | + Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, |
| 9661 | + (bodyResult) => { |
| 9662 | + if (bodyResult.status === Office.AsyncResultStatus.Failed) { |
| 9663 | + console.log(`Failed to get body: ${bodyResult.error.message}`); |
| 9664 | + return; |
| 9665 | + } |
9663 | 9666 |
|
9664 |
| - // Get the current body of the message or appointment. |
| 9667 | + // Add the Base64-encoded image to the end of the body. |
| 9668 | + const options = { isInline: true, asyncContext: bodyResult.value }; |
| 9669 | + Office.context.mailbox.item.addFileAttachmentFromBase64Async(base64String, "sample.png", options, (attachResult) => { |
| 9670 | + if (attachResult.status === Office.AsyncResultStatus.Failed) { |
| 9671 | + console.log(`Failed to attach file: ${attachResult.error.message}`); |
| 9672 | + return; |
| 9673 | + } |
9665 | 9674 |
|
9666 |
| - mailItem.body.getAsync(Office.CoercionType.Html, (bodyResult) => { |
9667 |
| - if (bodyResult.status === Office.AsyncResultStatus.Succeeded) { |
9668 |
| - // Insert the Base64-encoded image to the beginning of the body. |
9669 |
| - const options = { isInline: true, asyncContext: bodyResult.value }; |
9670 |
| - mailItem.addFileAttachmentFromBase64Async(base64String, "sample.png", options, (attachResult) => { |
9671 |
| - if (attachResult.status === Office.AsyncResultStatus.Succeeded) { |
9672 |
| - let body = attachResult.asyncContext; |
9673 |
| - body = body.replace("<p class=MsoNormal>", `<p class=MsoNormal><img src="cid:sample.png">`); |
9674 |
| - |
9675 |
| - mailItem.body.setAsync(body, { coercionType: Office.CoercionType.Html }, (setResult) => { |
9676 |
| - if (setResult.status === Office.AsyncResultStatus.Succeeded) { |
9677 |
| - console.log("Inline Base64-encoded image added to the body."); |
9678 |
| - } else { |
9679 |
| - console.log(setResult.error.message); |
9680 |
| - } |
9681 |
| - }); |
9682 |
| - } else { |
9683 |
| - console.log(attachResult.error.message); |
| 9675 | + let body = attachResult.asyncContext; |
| 9676 | + body += '<img src="cid:sample.png" />'; |
| 9677 | + |
| 9678 | + Office.context.mailbox.item.body.setAsync(body, { coercionType: Office.CoercionType.Html }, (setResult) => { |
| 9679 | + if (setResult.status === Office.AsyncResultStatus.Failed) { |
| 9680 | + console.log(`Failed to set body: ${setResult.error.message}`); |
| 9681 | + return; |
9684 | 9682 | }
|
| 9683 | + |
| 9684 | + console.log("Inline Base64-encoded image added to the end of the body."); |
9685 | 9685 | });
|
9686 |
| - } else { |
9687 |
| - console.log(bodyResult.error.message); |
9688 |
| - } |
| 9686 | + }); |
9689 | 9687 | });
|
9690 | 9688 | 'Office.Body#getTypeAsync:member(1)':
|
9691 | 9689 | - >-
|
|
9775 | 9773 | https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/20-item-body/add-inline-base64-image.yaml
|
9776 | 9774 |
|
9777 | 9775 |
|
9778 |
| - const mailItem = Office.context.mailbox.item; |
| 9776 | + // Get the current body of the message or appointment. |
9779 | 9777 |
|
9780 |
| - const base64String = |
9781 |
| - "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAnUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN0S+bUAAAAMdFJOUwAQIDBAUI+fr7/P7yEupu8AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAF8SURBVGhD7dfLdoMwDEVR6Cspzf9/b20QYOthS5Zn0Z2kVdY6O2WULrFYLBaLxd5ur4mDZD14b8ogWS/dtxV+dmx9ysA2QUj9TQRWv5D7HyKwuIW9n0vc8tkpHP0W4BOg3wQ8wtlvA+PC1e8Ao8Ld7wFjQtHvAiNC2e8DdqHqKwCrUPc1gE1AfRVgEXBfB+gF0lcCWoH2tYBOYPpqQCNwfT3QF9i+AegJfN8CtAWhbwJagtS3AbIg9o2AJMh9M5C+SVGBvx6zAfmT0r+Bv8JMwP4kyFPir+cswF5KL3WLv14zAFBCLf56Tw9cparFX4upgaJUtPhrOS1QlY5W+vWTXrGgBFB/b72ev3/0igUdQPppP/nfowfKUUEFcP207y/yxKmgAYQ+PywoAFOfCH3A2MdCFzD3kdADBvq10AGG+pXQBgb7pdAEhvuF0AIc/VtoAK7+JciAs38KIuDugyAC/v4hiMCE/i7IwLRBsh68N2WQjMVisVgs9i5bln8LGScNcCrONQAAAABJRU5ErkJggg=="; |
| 9778 | + Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, |
| 9779 | + (bodyResult) => { |
| 9780 | + if (bodyResult.status === Office.AsyncResultStatus.Failed) { |
| 9781 | + console.log(`Failed to get body: ${bodyResult.error.message}`); |
| 9782 | + return; |
| 9783 | + } |
9782 | 9784 |
|
9783 |
| - // Get the current body of the message or appointment. |
| 9785 | + // Add the Base64-encoded image to the end of the body. |
| 9786 | + const options = { isInline: true, asyncContext: bodyResult.value }; |
| 9787 | + Office.context.mailbox.item.addFileAttachmentFromBase64Async(base64String, "sample.png", options, (attachResult) => { |
| 9788 | + if (attachResult.status === Office.AsyncResultStatus.Failed) { |
| 9789 | + console.log(`Failed to attach file: ${attachResult.error.message}`); |
| 9790 | + return; |
| 9791 | + } |
9784 | 9792 |
|
9785 |
| - mailItem.body.getAsync(Office.CoercionType.Html, (bodyResult) => { |
9786 |
| - if (bodyResult.status === Office.AsyncResultStatus.Succeeded) { |
9787 |
| - // Insert the Base64-encoded image to the beginning of the body. |
9788 |
| - const options = { isInline: true, asyncContext: bodyResult.value }; |
9789 |
| - mailItem.addFileAttachmentFromBase64Async(base64String, "sample.png", options, (attachResult) => { |
9790 |
| - if (attachResult.status === Office.AsyncResultStatus.Succeeded) { |
9791 |
| - let body = attachResult.asyncContext; |
9792 |
| - body = body.replace("<p class=MsoNormal>", `<p class=MsoNormal><img src="cid:sample.png">`); |
9793 |
| - |
9794 |
| - mailItem.body.setAsync(body, { coercionType: Office.CoercionType.Html }, (setResult) => { |
9795 |
| - if (setResult.status === Office.AsyncResultStatus.Succeeded) { |
9796 |
| - console.log("Inline Base64-encoded image added to the body."); |
9797 |
| - } else { |
9798 |
| - console.log(setResult.error.message); |
9799 |
| - } |
9800 |
| - }); |
9801 |
| - } else { |
9802 |
| - console.log(attachResult.error.message); |
| 9793 | + let body = attachResult.asyncContext; |
| 9794 | + body += '<img src="cid:sample.png" />'; |
| 9795 | + |
| 9796 | + Office.context.mailbox.item.body.setAsync(body, { coercionType: Office.CoercionType.Html }, (setResult) => { |
| 9797 | + if (setResult.status === Office.AsyncResultStatus.Failed) { |
| 9798 | + console.log(`Failed to set body: ${setResult.error.message}`); |
| 9799 | + return; |
9803 | 9800 | }
|
| 9801 | + |
| 9802 | + console.log("Inline Base64-encoded image added to the end of the body."); |
9804 | 9803 | });
|
9805 |
| - } else { |
9806 |
| - console.log(bodyResult.error.message); |
9807 |
| - } |
| 9804 | + }); |
9808 | 9805 | });
|
9809 | 9806 | 'Office.Body#setSelectedDataAsync:member(1)':
|
9810 | 9807 | - >-
|
|
0 commit comments