473,748 Members | 4,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML Emails, General Handling Of HTML strings

We are writing a dotnet app that among other things retrieves messages from
a standard POP3 mailbox, and then performs certain actions with that email
automatically.

Some of the emails are coming in as HTML, which makes the email itself 8
times as large when it comes time to store it, as well as makes it
impossible to display to the user using any sort of standard dotnet control.

Is there a way to STRIP OUT all the html tags and get plain text from it? I
know it is possible, and somewhat easy, as IE can save html as plain text,
and Outlook can easily save the Emails themselves as plain text. All I have
found so far to get this done is some kludgey search and replace routines.

Additionally, does anyone know of a textbox control that can actually
display simple html? I don't think a rich text can, or I can't seem to get
it to.

Thanks....


Nov 20 '05 #1
7 1750
there are browser tools built-in to display html...but anyway...

this strips all tags, so you may want to clean it up by replacing <br>, <p>,
</div>, etc. with vbCrLf to keep some kind of formatting...el se this gives
you the string as is and doesn't remove the source vbCrLf's that may/not
effect how the text would appear in the browser.

having said that...hth,

steve

Imports System.Text
Imports System.Text.Reg ularExpressions
Imports System.Web
Imports System.Web.Http Utility

Public Function stripTags(ByVal html As String) As String
Dim tagPattern As String = "<[^>]*>"
Dim regEx As New Regex(tagPatter n)
If Not regEx.IsMatch(h tml, tagPattern) Then Return Nothing
html = regEx.Replace(h tml, tagPattern, " ")
html = HttpUtility.Htm lDecode(html) ' convert stuff like &gt; &trade; etc.
Return html
End Function
Nov 20 '05 #2
* "Tappy Tibbons" <ta**********@s bcglobal.net> scripsit:
We are writing a dotnet app that among other things retrieves messages from
a standard POP3 mailbox, and then performs certain actions with that email
automatically.

Some of the emails are coming in as HTML, which makes the email itself 8
times as large when it comes time to store it, as well as makes it
impossible to display to the user using any sort of standard dotnet control.

Is there a way to STRIP OUT all the html tags and get plain text from it? I
know it is possible, and somewhat easy, as IE can save html as plain text,
and Outlook can easily save the Emails themselves as plain text. All I have
found so far to get this done is some kludgey search and replace routines.

Additionally, does anyone know of a textbox control that can actually
display simple html? I don't think a rich text can, or I can't seem to get
it to.


You can use the WebBrowser control to display HTML:

311303 WebOCHostVB.exe Hosts the WebBrowser Control in Visual Basic .NET
<http://support.microso ft.com/?id=311303>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #3
Cor

"Tappy Tibbons
Is there a way to STRIP OUT all the html tags and get plain text from it? I know it is possible, and somewhat easy, as IE can save html as plain text,
and Outlook can easily save the Emails themselves as plain text. All I have found so far to get this done is some kludgey search and replace routines.

To strip out tags I would use mshtml (you have to set a reference to it and
when you use it don't set the import, you there are so many objects in that
you'r Ide becomes terrible slow, the best to use is
Dim iDocument As mshtml.IHTMLDoc ument2)
You can loop for each tag in the document object model way.

For to see the HTML tag is of course the normal textbox, that is the same as
the old and still used HTML editor Notepad.

To see it in browser look the already by Herfried mentioned webbrowser.

I hope this helps a little bit?

Cor
Nov 20 '05 #4
Hi Tappy,

I wanted to answer this hours ago. Thanks to Cor, I can do so now.

If you add the Microsoft Web Browser control (ShDocVw.) to your ToolBox
and drag it onto your Form, you can use the Navigate2 (sUrl) method to load a
page. Once the page is loaded (ie. <not> in the next statement) you can access
the Document property. This gives you practically the full range of things as
if you were writing JavaScript or VbScript within an Html page.

So to get a page you could have.
axWebBrowser1.N avigate2 ("http://www.google.co.u k")

The Document will be available when the AxWebBrowser1.D ocumentComplete
event occurs.

In the handler for this event you can do
Dim oHtmlDoc = axWebBrowser1.D ocument
Dim oBody = oHtmlDoc.Body

Then this will give you the text with no Html.
TextBox1.Text = oBody.InnerText

To display your own Html in the browser you just need to stuff it into the
Body.

oBody.InnerHtml = "<div style='backgrou nd-color:yellow'>" _
& "<h1>Hi Tappy!!</h1></div>"

(And it needn't be 'simple' Html, after all, this is the engine of
Internet Explorer in your app!!)

The bits I'm not sure of are the types for oHtmlDoc and oBody. That's why
they're missing from the declarations (and Option Strict is definitely Off).

Regards,
Fergus
Nov 20 '05 #5
Hi again Tappy,

I forgot to add the documentation:
Start here and work your way up and down.

Programming and Reusing the Browser
WebBrowser Control
Reference for Visual Basic Developers

http://tinyurl.com/t3vf

You'll probably get most use out of the link to the Document property on
the page given, and then that page's IHtmlDocument2 link.

Have fun. ;-)

Regards,
Fergus

The Tiny Url is the equivalent of:

http://msdn.microsoft.com/library/de...ser/webbrowser
/webbrowser.asp
Nov 20 '05 #6
* "Fergus Cooney" <fi****@post.co m> scripsit:
The Tiny Url is the equivalent of:

http://msdn.microsoft.com/library/de...ser/webbrowser
/webbrowser.asp


You may want to install the patches for OE in order to prevent it from
wrapping urls. I remember the "mondo" patch fixed this issue.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
HERFRIED

GET OFF MY BACK.

I WANT NOTHING FROM YOU

NOTHING

NOTHING AT ALL

ABSOLUTELY NOTHING

CAN YOU COMPLY?
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3130
by: simonc | last post by:
I've been programming in assembler and C/C++ for a number of years, but I'm only just starting down the road of PHP & MYSQL. I have a couple of questions: (1) Before I start writing my own code, to learn from, and also avoid re-inventing the wheel, does anyone know of any existing source that implements a (basic or complex) play-by-email system using PHP and maybe MYSQL?
1
2893
by: dan glenn | last post by:
I'm creating HTML emails from a PHP site and sending them out to an email list (just about 40 people so far are on this list). I've tested and confirmed that these emails work in yahoo.com's webmail. And I know they work on *my* Outlook Express. But I have one person (I know of) who gets the emails as plain text, so she sees the HTML code for the email instead of its proper representation. She has, like myself, OE6, and other html emails...
4
4341
by: Ann | last post by:
Hi, I am trying to send a html email from a php script. This script emails a common information to all the members in the database. The only problem is I cannot specify colors, hyperlinks etc..Html tags like <h1></h1>, <br/>, <b> etc works though.. Could any one tell me what i might be doing wrong? Any help will be greatly appreciated.
4
3922
by: Benny Ng | last post by:
Hi, I have written a program in vb6 that can send and receive emails but how can i store them? Benny
1
3266
by: Sean W. Quinn | last post by:
Hey folks, I have a question regarding file handling, and the preservation of class structure. I have a class (and I will post snippets of code later in the post) with both primitive data structures (ints), and more complex data structures (strings and vectors) in it, and would like to write the entire class to a data file that could then be read back and loaded. However I'm having difficulty with this -- I found out (due to an...
5
5185
by: Ghazan Haider | last post by:
When you have a long string like aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa in an html table, it pushes the table out so you have to scroll to the right. I've tried width=100%, width=500, both in the <td> and in <table>, have tried all the stylesheet suggestions I've found in google and it doesnt work. Ideally I'd rather have the text force-wrapped, else just hidden than breaking...
59
7027
by: Lennart Björk | last post by:
Hi All, I have a tiny program: <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>MyTitle</title> <meta http-equiv="Content-Type" content="text/html;
21
2733
by: maya | last post by:
hi, I'm designing an HTML email for a client.. I know general guidelines (no CSS, no JavaScript... although I do use limited CSS, inside tags (as in <span style=".."we do this at work and it works fine, so I figured it's ok..) but I have a few more questions, for example, is it ok to do client-side image-maps? is there a web page somewhere with general guidelines for HTML e-mails? (and what is best way to test HTML e-mails? (I...
13
1553
by: Fulvio | last post by:
*********************** Your mail has been scanned by InterScan MSS. *********************** Hello, I'd like to ask some clue to move further on my project :-) The purpose would be to gather all emails (local and remote ones) to do some backup.
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.