HTML | Blog | Limilabs https://www.limilabs.com/blog Using Limilabs .net components Sun, 03 Jun 2012 13:12:50 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 Create HTML from plain text email https://www.limilabs.com/blog/create-html-from-plain-text-email Thu, 12 Apr 2012 09:23:07 +0000 http://www.limilabs.com/blog/?p=2629 Mail.dll MIME and email component may be used to retrieve plain-text body or HTML body from an email message. If a message contains HTML, no conversion is necessary. You just need to use HTML property of IMail interface. If however an email does not contain HTML and only plain-text content is available, many times plain-text […]

The post Create HTML from plain text email first appeared on Blog | Limilabs.

]]>
Mail.dll MIME and email component may be used to retrieve plain-text body or HTML body from an email message.

If a message contains HTML, no conversion is necessary. You just need to use HTML property of IMail interface.

If however an email does not contain HTML and only plain-text content is available, many times plain-text needs be converted to HTML.

You can use GetBodyAsHtml method that always returns body in HTML format (it uses IMail.HTML property or creates valid HTML from IMail.Text).

// C#

IMail email = ...

string html = email.GetBodyAsHtml();
Console.WriteLine(html);

' VB.NET

Dim email As IMail = ...

Dim html As String = email.GetBodyAsHtml()
Console.WriteLine(html)

The post Create HTML from plain text email first appeared on Blog | Limilabs.

]]>
Extract plain text from HTML email https://www.limilabs.com/blog/extract-plain-text-from-html-email Tue, 27 Dec 2011 16:59:24 +0000 http://www.limilabs.com/blog/?p=2185 Mail.dll MIME and email component may be used to get the plain-text body and HTML body from any email message. If a message contains plain-text, no conversion is necessary. It’s simply a matter of using the Text property of IMail interface. If however the email does not contain plain-text and only HTML content is available, […]

The post Extract plain text from HTML email first appeared on Blog | Limilabs.

]]>
Mail.dll MIME and email component may be used to get the plain-text body and HTML body from any email message.

If a message contains plain-text, no conversion is necessary. It’s simply a matter of using the Text property of IMail interface.

If however the email does not contain plain-text and only HTML content is available, GetTextFromHtml method may be used to convert the HTML to plain-text.

The internal conversion process is much more sophisticated than what can be accomplished with the simple regular-expression code. Converting HTML to plain text is much more than simply removing HTML tags from an HTML document.

Mail.dll contains full-blown HTML parser that handles script tags, comments, CDATA and even incorrectly formatted HTML.

The following C# and VB.NET code extracts plain-text from the HTML body of the email message:

// C#

IMail email = ...

string text = ""; 
if (email.IsText)
    text = email.Text;
else if (email.IsHtml)
    text = email.GetTextFromHtml();
Console.WriteLine(text);

' VB.NET

Dim email As IMail = ...

Dim text As String = ""
If email.IsText Then
    text = email.Text
ElseIf email.IsHtml Then
    text = email.GetTextFromHtml()
End If
Console.WriteLine(text)

You can also use GetBodyAsText method that returns body in plain text format (it uses IMail.Text property or GetTextFromHtml method).

// C#

IMail email = ...

string text = email.GetBodyAsText();
Console.WriteLine(text);

' VB.NET

Dim email As IMail = ...

Dim text As String = email.GetBodyAsText()
Console.WriteLine(text)

The post Extract plain text from HTML email first appeared on Blog | Limilabs.

]]>