How to read emails that contain both mime-part (text/html and text/plain)

How to read emails that contain both mime-part (text/html and text/plain)?

When reading emails via IMAP protocol (Using the "Get IMAP Mail" - Activity) it  can only read mails that contain only one text mime-part (text/html or text/plain). Since most of the received emails contain more than one text/... - mime-part, when using System.NET.Mail you could receive a NULL-string when emails contain both mime parts

To be able to read emails that contain both mime-parts the email can be processed using Regular Expression: 
1.Use a get IMAP message activity; it’s result will be a list of mail messages.
2. Use a for each loop with type argument System.Net.Mail.MailMessage
3.In the above regex, ‘item’ is each MailMessage item in the list of mailmessages.
4.Assign string with one of the following, mail_body=

  • System.Text.RegularExpressions.Regex.Replace(item.Headers(“HTMLBody”),"(<.*?>)|({.*})|(.*[}\)--{;]\s?\r\n)|(\r?\n@.*)|(.*[}{;]$)",String.Empty).Trim

  • System.Text.RegularExpressions.Regex.Replace(item.Headers(“HTMLBody”),"(<.*?>)|({.*})|(.*[}\)--{;]\s?\r\n)|(\r?\n@.*)|(.*[}{;]$)",String.Empty)

5. Now 'mail_body' holds the captured plain text from the HTML mail

Image_2019-11-29_13-24-52.png