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 a NULL-string could be received 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:
- Use a get IMAP message activity; it’s result will be a list of mail messages.
- Use a for each loop with type argument System.Net.Mail.MailMessage
- In the above regex, ‘item’ is each MailMessage item in the list of mailmessages.
- 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)
- Now 'mail_body' holds the captured plain text from the HTML mail