Get IMAP Mail activity - Unable to get all mime-parts (text/html or text/plain)

How to fetch the email body of a mail message that contains text/html or text/plain content?

While fetching emails using the Get IMAP Mail Message activity, by default, it can only read mails that contain only one text mime-part (text/html or text/plain). When received emails contain more than one text/... mime-part, it might return a null string.

  1. Use a Get IMAP Mail Message activity that gives an output of List of MailMessage.
  2. Use a For each loop with the type argument System.Net.Mail.MailMessage
  3. 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

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

  4. In the regex above, ‘item’ is each MailMessage item in the List of MailMessage
  5. 'mail_body' holds the captured plain text from the HTML mail