sending html formatted mail through vb .net

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

The following code works fine:
Dim sr As StreamReader = New StreamReader("c:\htdogpro\bhome.htm")

htmstring = sr.ReadToEnd()

msg.Body = htmstring

msg.BodyFormat = MailFormat.Html ' as opposed to mailformat.text

However, if the htm file has images, they do not go along with the text
stream. How can I include the images that the htm file uses?

Thanks for any help.

Bernie Yaeger
 
Bernie,

Images would have to be embedded in attachments of the mail message itself,
if you look at spam, they don't include the images in the message itself,
but on a public webserver outside of it.

To send the messages themselves with images is a huge bandwidth hog on mail
servers.
 
Bernie,

* "Bernie Yaeger said:
Dim sr As StreamReader = New StreamReader("c:\htdogpro\bhome.htm")

htmstring = sr.ReadToEnd()

msg.Body = htmstring

msg.BodyFormat = MailFormat.Html ' as opposed to mailformat.text

However, if the htm file has images, they do not go along with the text
stream. How can I include the images that the htm file uses?

I didn't test it, but maybe it will work better with Indy:
<http://www.indyproject.org/indy.html>.
 
From a practical standpoint doesn't this look like streamreader is the
cause?

I could be out to lunch but it would have to "read the stream" and notice
there was a reference to a supported graphic type and decide to load that
too despite it being in a "different" stream (does it open it read-only?)
and then it encounters what looks like a reference to a 20 minute video file
and so it reads that too. :-)

I'm not certain I want streamreader to be that clever,
Tom
 
Thanks CJ - I think I have to answer from your suggestions - I can call each
image from an internet site - eg, http:// etc - where the images reside.

Thanks again,

Bernie
 
* "Tom Leylan said:
From a practical standpoint doesn't this look like streamreader is the
cause?

Yes and no. The HTML file doesn't include the graphics files, it only
references them.
I could be out to lunch but it would have to "read the stream" and notice
there was a reference to a supported graphic type and decide to load that
too despite it being in a "different" stream (does it open it read-only?)
and then it encounters what looks like a reference to a 20 minute video file
and so it reads that too. :-)

I'm not certain I want streamreader to be that clever,

'StreamReader' isn't that clever, but you can provide a class
'TomsToolbox.HtmlStreamReader' or something similar :-).
 
Perhaps I misunderstood...

Is there a replacement for StreamReader in the Indy library which analyzes
the file it is reading and decides which files to imbed? It could be I have
it entirely wrong but it seems... well let me use the term "unlikely."

If it has such a feature would you let us know?

Again... I'm probably phrasing things wrong. What makes you think that Indy
might be able to produce alternative results... that might be what I'm
trying to ask.
 
Exactly.

no problem,.

CJ
Bernie Yaeger said:
Thanks CJ - I think I have to answer from your suggestions - I can call each
image from an internet site - eg, http:// etc - where the images reside.

Thanks again,

Bernie
 
Hi Tom,

Frankly, I love your idea - but the streamreader (or component) would have
to be pretty smart to do what you suggest. But the more I think of it, yes,
it should be able to! Great idea.

Bernie

Tom Leylan said:
Perhaps I misunderstood...

Is there a replacement for StreamReader in the Indy library which analyzes
the file it is reading and decides which files to imbed? It could be I have
it entirely wrong but it seems... well let me use the term "unlikely."

If it has such a feature would you let us know?

Again... I'm probably phrasing things wrong. What makes you think that Indy
might be able to produce alternative results... that might be what I'm
trying to ask.



Herfried K. Wagner said:
Yes and no. The HTML file doesn't include the graphics files, it only
references them.
video
 
Hi Bernie,

I fear that I've been misunderstood. No problem though as decades of
misunderstandings have made me quite immune to this :-) But... how would it
"know" which things in the text file (and don't for a moment think that a
file with an HTM extension isn't a text file) should read using the same
settings as it used to read the text file?

You can't read any old graphics format with the same settings as you read a
text file. They aren't the same format, you may not have the proper
permissions, you didn't explain what to do if one of the potentially many
"subfiles" turns out to not be available, etc. Try it from this
direction... it encounters ".pdf" as as an extension... and? What do you
hope it will do? Use your copy of the .pdf reader, the one you think you
the client has? Some version in cyberspace? It had better fail just to
behave normally :-)

It not only can't if it ever could it shouldn't... :-)

I'm still trying to figure out why Herfried thought that some other TCP/IP
library would make a difference. It's not a bad idea, I'm just wondering
how people's minds work. These are computers... why not suppose that cars
know where we want to go and have them simply drive us there?


Bernie Yaeger said:
Hi Tom,

Frankly, I love your idea - but the streamreader (or component) would have
to be pretty smart to do what you suggest. But the more I think of it, yes,
it should be able to! Great idea.

Bernie
 
Hi Bernie,
The following code works fine:
Dim sr As StreamReader = New StreamReader("c:\htdogpro\bhome.htm")

Did you test this also with webpages with frames?

Just curious if this works, I am asuming that this does not work also?

Cor
 
Hi Tom,

Why so difficult? Parsing a string isn't all that hard. How many key
strings need the component parse - .pdf, .gif, .png, .jpg - then, too,
<http, <href and various other tags, all of which is done now by the html
spec.

No, you're not giving yourself enough credit :-)

Bernie
 
Hi Cor,

No; I haven't tested with frames; interesting idea, because that would
require at least the frameset page and the regular page.

Bernie
 
Bernie... I appreciate the vote of confidence :-)

Parsing isn't as easy as you make out but you're asking StreamReader to do
it. It might make it troublesome to read a stream that happens to contain
what could be interpreted as a reference to a graphics image. Generally
speaking you would want it to recognize every format that could conceivably
be represented on an HTML page... I'll quote from the W3C site:
http://www.w3.org/Graphics/

"There is no limit in the Web specifications to the graphical formats that
can be used on the Web. You just need a MIME type so that the format is
labelled correctly for transfer across the Web, and so that a suitable
viewer (if one exists) can be located at the other end."

I'm not against somebody offering a library to do such a thing but I would
be a little concerned about a basic StreamReader class trying to handle it
all. Remember it isn't just about images. I'd have to locate a video and
audio formats page but I'm sure you get the point :-)
 
Back
Top