I am developing Outlook web addin using office JS.
This addin encrypts & decrypts the message.
Go through below scenario :
- The sender trying to compose the mail
- The sender adds the inline image in the mail body
- HTML of that email will be as below :
<img src="https://attachment.outlook.live.net/owa/MSA%3Abhavesh-
mishra%40outlook.com/service.svc/s/GetAttachmentThumbnail?
id=thumbnailType=2&isc=1&token=CANARY=&owa=outlook.live.com
&scriptVer=20230505004.08&animation=true"
style="max-width:100%"
class="ContentPasted0 w-205 h-26"
originalsrc="cid:6f30b494-65bf-466a-8faf-3dd6f8b0fcbf"
size="211"
contenttype="image/png">
- The mail will be encrypted while sender sends the email. Above HTML of the image will also be encrypted.
- At the receiver side,When the receiver clicks on the 'decrypt' button, Whole body content is showing decrypted in the Addin task panel. But the image is showing crashed.
- When I am hitting that image URL in browser, It showing "440 Login Timed Out".
To resolve this, I have added logic to convert those images to base64 string & Encrypt it. To convert those images to base64 string, I reffered this.
Before saving the mail (As shown in above link), I am setting internet headers by using this.
mail_item.internetHeaders.setAsync(internet_headers, function (set_headers_response) {});
I came to know that when there is inline image in the outlook mail body, The internet headers are not setting and throwing below error :
Sys.ArgumentTypeException: Object Of Type 'object' Can't Be Converted To Type 'string'
When there is plain text in the body of the outlook mail, Internet headers are added successfully.
This is the flow of method which encrypts the mail and sends it :
mail_item.body.getAsync
- API call which accepts content of the mail and returns encrypted content
mail_item.loadCustomPropertiesAsync()
to set custom properties usingset("key","value")
method- Setting internet headers by using
mail_item.internetHeaders.setAsync({"key":"value"}, function (set_headers_response) {});
- Converting images to base64 string by reffering this.
- Saving the mail and setting email body with encrypted content by using
mail_item.saveAsync()
&mail_item.body.setAsync()
respectively. - Mail sent
So now actually I am suffering from below two issues :
- How to convert inline images to base64 string using JS.
- How to set internet headers when there is inline images in the outlook mail body.