Thursday, 14 August 2014 09:25

E-Mail Body in Plain Text

Rate this item
(0 votes)

Erstellt am Donnerstag, 14. August 2014 Geschrieben von Stefan Horz

If you use the Integration Pack for Exchange Users the Published Data {Body from “Get Item”} is shown with HTLM tags getting a HTML formatted email.

Body with HTML Tags

For further automation and integration you may need the body in plain text.

Therefore I modified PowerShell script I found searching the Internet for PowerShell to convert HTLM in plain text (http://winstonfassett.com/blog/2010/09/21/html-to-text-conversion-in-powershell/) and run it with the "Run .Net Script" Activtity.

BodyasPlainText

Copy the script in the Details tab and subscribe the Published Data {Body from "Get Item"}.

PainText in Powershell

Use tab “Published Data” publish the variable $plaintext to the data bus.

Plain Text to Databus

Here’s the modified script I use:

$html = @'
{Body from "Get Item"}
'@

# remove line breaks, replace with spaces
#$html = $html -replace "(`r|`n|`t)", " "

# remove invisible content
@('head', 'style', 'script', 'object', 'embed', 'applet', 'noframes', 'noscript', 'noembed') | % {
$html = $html -replace "]*?>.*?", ""
}

# Condense extra whitespace
$html = $html -replace "( )+", " "

# Add line breaks
@('div','p','blockquote','h[1-9]') | % { $html = $html -replace "]*?>.*?", ("`n" + '$0' )}
# Add line breaks for self-closing tags
@('div','p','blockquote','h[1-9]','br') | % { $html = $html -replace "]*?/>", ('$0' + "`n")}

#strip tags
$html = $html -replace "]*?>", ""
# write-verbose "removed tags: `n`n$html`n"

# replace common entities
@(
@("•", " * "),
@("&lsaquo;", "<"),
@("&rsaquo;", ">"),
@("&(rsquo|lsquo);", "'"),
@("&(quot|ldquo|rdquo);", '"'),
@("&trade;", "(tm)"),
@("&frasl;", "/"),
@("&(quot|#34|#034|#x22);", '"'),
@('&(amp|#38|#038|#x26);', "&"),
@("&(lt|#60|#060|#x3c);", "<"),
@("&(gt|#62|#062|#x3e);", ">"),
@('&(copy|#169);', "(c)"),
@("&(reg|#174);", "(r)"),
@("&nbsp;", " "),
@("&(.{2,6});", ""),
@(" ", " ")

) | % { $html = $html -replace $_[0], $_[1] }

$plaintext=$html

Read more

Leave a comment