How to detect the format of the email being composed in an Outlook Add-in? - outlook-web-addins

I saw that Office.context.mailbox.item.body.setSelectedDataAsync() would fail if called with options.coercionType set to Office.CoercionType.Html when the message body is in plain text.
I was wondering if there was any way to check what the format of the message body is before I called setSelectedDataAsync?

You would need to use getTypeAsync method of the body object. Even more, this is suggested way to insert any data into the mail item's body. Before inserting, you should always first verify the supported item format by calling getTypeAsync. Please read more on the topic how to Insert data in the body when composing an appointment or message in Outlook in the Outlook API documentation.

Related

Azure Logic app read my approval email in form of HTML tags

I have created a Azure Logic app to read the email body and check for the condition - If the email body 1st line has the only word called "Approved", then trigger another process or else do nothing.
But when performing it, I could see the condition gets to false even though the mail has only Approved word in it accommodated with signatures in the bottom. After researching, I could see the email is being read like HTML tags. So i created two more variable to extract a part of this e-mail and check for condition.
EmailBodyTrimmed = trim(substring(toUpper(replace(replace(trim(variables('EmailBody')),' ',''),'.',''),),0,500))
EmailBodyTrimmedFinal = trim(substring(trim(replace(trim(variables('EmailBodyTrimmed')),' ','')),0,indexOf(replace(variables('EmailBodyTrimmed'),' ',''),'<')))
But nothing seems to give correct answer. Can anyone help me ?
I think you can use Body Preview to receive the body of the email:
According to my test results, it receives the text in non-HTML format, so you don't have to extract the body from the HTML text.
Then you only need to add a condition and use starts with to determine whether it starts with approved.
Of course, this premise is that your email body is in plain text format, if it is in excel format, you need to do other processing.

download signed document as JSON from docusign

It seems that docusign only supports downloading the signed documents as PDF instead of JSON.
I need to 'read' the filled fields of the documents (the document has some fields to fill in).
I can upload the document as JSON and it gets parsed, so why can't I donwload it as JSON?
How do companies normally handle the field values?
Thanks!
You don't need the actual PDF document to get the values, you need to parse the call coming back from DocuSign since that has total envelope data. The webhooks for notification contains the data and you can parse that to retrieve the envelope data.
Do you know if its also possible with a GET call instead of the webhook? It could be the server is down etc, so I can't imagine DocuSign does have something like GET:envelope/:id/data or something.. But really cannot find anything like it
Yes. You can either use a GET call (included below) any time you want to get envelope data or you can set up the webhooks so that DocuSign will send you updates whenever it has one!
The following GET call retrieve envelope data from {{envelopeId}}. By parsing the response from the call you can retrieve all information that was filled on the envelope.
{{baseUrl}}/envelopes/{{envelopeId}}/recipients?include_tabs=true
I hope this helps.
P.S. Summarized our comments to have a complete answer.
The PDF format is, for lack of better words, a complicated jumble of compiled data that can be difficult to parse. What it appears docusign will do is take the data provided and fill the PDF document fields that are previously identified.
With docusign returning the PDF, you will need to parse the PDF input fields to receive the field values. There are several libraries that can be used to parse the various form fields and do what you would like. Check out:
https://www.npmjs.com/package/pdfreader
https://www.npmjs.com/package/pdf2json
I am sure there are more that would work for you as well if you look around if these don't work for you.

Copy the Outlook mail body content to WORD Document using Python

I want to write a python program that copies the contents of outlook mail body (Mail body : contains the tables) pastes it to word document.
import win32com.client
import pythoncom
class Handler_Class(object):
def OnNewMailEx(self, receivedItemsIDs):
for ID in receivedItemsIDs.split(",")
mailItem = outlook.Session.GetItemFromID(ID)
print(mailItem.Body)
outlook = win32com.client.DispatchWithEvents("Outlook.Application", Handler_Class)
pythoncom.PumpMessages()
when I try to print mail body using “print(mailItem.Body)” table contents are displayed as text, not as a table format.
Could anyone help me how to export the mailbody content to the word document without changing its format using python.
First of all, there is no need to split the string passed to the NewMailEx event of the Application class.
The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. The EntryIDsCollection string contains the Entry ID that corresponds to that item. Note that this behavior has changed from earlier versions of the event when the EntryIDCollection contained a list of comma-delimited Entry IDs of all the items received in the Inbox since the last time the event was fired. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously.
The Outlook object model provides three main ways for working with item bodies:
Body.
HTMLBody.
The Word editor. The WordEditor property of the Inspector class returns an instance of the Word Document which represents the message body. So, you can use the Word object model do whatever you need with the message body. You can get access to the Document which represents the message body and copy/paste the required range or paragraph.
You can read more about all these ways in the Chapter 17: Working with Item Bodies in MSDN.

In Outlook REST API how can I set BodyType to Text

I EWS, I was able to specify BodyType = 'Text' when querying email messages. Is there any alternative to this in Outlook REST api?
I tried to use PidTagBody property which is a plain text representation of message body, but it just seems to be empty for all messages with Html body type.
Thanks.

Fetching all unseen email (body + attachment) with node-imap

I am writing a simple software that needs to:
Connect to an IMAP server
Download all unread messages
Store each message's body, and attachment. I prefer the body as text.
Mark them as read
I am reading https://github.com/mscdex/node-imap; however, a message can be in multiple parts, and that's where I am lost. For example, when it's multi-part, what is the part that is guaranteed to be the actual email body?
Or, even better, is there a wrapper out there that will just return a nice "message" object, all neatly fetched and prepared for me? Something with the usual headers (from, to, etc.), to body, and a bunch of pre-decoded attachment?
Merc.
To answer the good part of your question: No part is guaranteed to be "the email body", you can legally send a message without text. I've seen software that'll send attachment-only mail when the user adds an attachment but leaves the mail body field empty. The way to distinguish between inline bodies and attachments is to look at the content-disposition field, and if that's not present, assume inline for text/* and attachment for other types. (Yes, this also means that there may be more than one inline body. Apple Mail is fond of sending that, for instance.)
The other part of your question is a FAQ and an easy one, and yes, there's much software to build that message object. Approximately 100% of client libraries can do that. Search your documentation for "bodystructure", that's the name of the IMAP fetch item they retrieve and parse in order to build the structure you want.

Resources