473,373 Members | 1,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,373 software developers and data experts.

How? Send Same Email as HTML *or* Plain Text

Hello. I'm looking for a simple way to do the following:

We have a database that serves-up content to a website. Some of those items
are events, some are news articles. They're stored in the DB as formatted
HTML so ASP just drops them right into a page shell.

Now, we want to send out a newsletter email containing some of those items.
No problem sending as HTML. However, some of the members want just plain
text. Is there some magic method in CDO that can automatically convert HTML
to plain text? Or, is there some existing VBScript code out there that can
do this?

BTW, the environment is IIS 5.x (Windows 2000), Classic ASP, and CDO.

Thanks...
Jul 19 '05 #1
10 4134
I don't think any company knows how to do this right. All the crap I get
looks horrible (Outlook is set to force all content to plain text).

I think the cleanest way to do it would be to store the content twice, or
store plain text and apply HTML to it after the fact.

--
http://www.aspfaq.com/
(Reverse address to reply.)


"J. Alan Rueckgauer" <vo**@dev.nul> wrote in message
news:#T**************@TK2MSFTNGP12.phx.gbl...
Hello. I'm looking for a simple way to do the following:

We have a database that serves-up content to a website. Some of those items are events, some are news articles. They're stored in the DB as formatted
HTML so ASP just drops them right into a page shell.

Now, we want to send out a newsletter email containing some of those items. No problem sending as HTML. However, some of the members want just plain
text. Is there some magic method in CDO that can automatically convert HTML to plain text? Or, is there some existing VBScript code out there that can do this?

BTW, the environment is IIS 5.x (Windows 2000), Classic ASP, and CDO.

Thanks...

Jul 19 '05 #2
If ur using CDO-NTS maybe have a look at HTMLText/Text properties of the Message object, using which depending on how recipient wishes to receive emails!?

"J. Alan Rueckgauer" wrote:
Hello. I'm looking for a simple way to do the following:

We have a database that serves-up content to a website. Some of those items
are events, some are news articles. They're stored in the DB as formatted
HTML so ASP just drops them right into a page shell.

Now, we want to send out a newsletter email containing some of those items.
No problem sending as HTML. However, some of the members want just plain
text. Is there some magic method in CDO that can automatically convert HTML
to plain text? Or, is there some existing VBScript code out there that can
do this?

BTW, the environment is IIS 5.x (Windows 2000), Classic ASP, and CDO.

Thanks...

Jul 19 '05 #3

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
I don't think any company knows how to do this right. All the crap I get
looks horrible (Outlook is set to force all content to plain text).

I think the cleanest way to do it would be to store the content twice, or
store plain text and apply HTML to it after the fact.

[snip]

Aaron --

The database contains just about all of the site's content, and they won't
go for having to maintain two separate versions of everything. (The end
users have enough trouble fathoming how a website works as it is.) OTOH, I
don't particularly relish writing a script from scratch to
search-and-destroy the HTML tags and preserve paragraphs. Do you happen to
know of one that's already out there that I can grab?

Thanks,
Alan
Jul 19 '05 #4
> If ur using CDO-NTS maybe have a look at HTMLText/Text properties of the
Message object, using which depending on how recipient wishes to receive
emails!?

Yes, CDO can use either plain text or HTML, and can even send both.
However, the plain text readers don't want to be bothered with getting both.
And I suspect the problem isn't a technical one in sending the mail in the
correct format... it's making the HTML content look good in plain text (or
vice versa).

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #5

"StephenMcC" <St********@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
If ur using CDO-NTS maybe have a look at HTMLText/Text properties of the Message object, using which depending on how recipient wishes to receive
emails!?

[snip]

The problem is creating the .TextBody. The source text is stored as HTML,
so wrapping <html><body> around it and plopping it in .HtmlBody is a
no-brainer. You can't just reassign the string for .HtmlBody to .TextBody:
it doesn't remove the HTML tags, so you get a text message that looks like
"<html><body><h1>This Week's News</h1></body></html>" which is absolutely
not what is wanted.
Jul 19 '05 #6
"J. Alan Rueckgauer" wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...

: "StephenMcC" <St********@discussions.microsoft.com> wrote in message
: news:61**********************************@microsof t.com...
: > If ur using CDO-NTS maybe have a look at HTMLText/Text properties of the
: Message object, using which depending on how recipient wishes to receive
: emails!?
: >
: [snip]
:
: The problem is creating the .TextBody. The source text is stored as HTML,
: so wrapping <html><body> around it and plopping it in .HtmlBody is a
: no-brainer. You can't just reassign the string for .HtmlBody to
..TextBody:
: it doesn't remove the HTML tags, so you get a text message that looks like
: "<html><body><h1>This Week's News</h1></body></html>" which is absolutely
: not what is wanted.

You would probably need to take 3 passes at it or have a more complex
Regular Expression but you could replace </p> with 2 vbCrLf, <br> or <br />
with 1 vbCrLf and then use a regexp to remove all HTML tags. Actually any
block elements should be replaced with vbCrLf.

Something like this...

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

' converts HTML email to plain text

dim re, str, r
str = lcase("<HTML><HEAD><TITLE></TITLE></HEAD><BODY><p>Heading</p>line 1<br
/>line 2<br />line 3</BODY></HTML>")
str = replace(str,"<br />",vbCrLf)
str = replace(str,"</p>",vbCrLf & vbCrLf)
set re = new RegExp
re.Pattern = "<[^>]*>"
re.Global = true
re.IgnoreCase = true
r = re.replace(str,"")
Response.Write(r)
set re = nothing
%>

You can see it here but you need to view the source to see how it would turn
out in an email.
http://kiddanger.com/lab/htmlx.asp

FYI.. My email is set to plain text. I get plain text but if it is HTML
formatted, then the HTML version is an attachment. I never see the HTML
code in my plain text message body.

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #7
I think you might need some conditionals in there, e.g. you might not want
to discard the HTML tag completely, for something like this:

<a href=http://www.mysite.com/>click here!</a>

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Roland Hall" <nobody@nowhere> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
"J. Alan Rueckgauer" wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...

: "StephenMcC" <St********@discussions.microsoft.com> wrote in message
: news:61**********************************@microsof t.com...
: > If ur using CDO-NTS maybe have a look at HTMLText/Text properties of the : Message object, using which depending on how recipient wishes to receive
: emails!?
: >
: [snip]
:
: The problem is creating the .TextBody. The source text is stored as HTML, : so wrapping <html><body> around it and plopping it in .HtmlBody is a
: no-brainer. You can't just reassign the string for .HtmlBody to
.TextBody:
: it doesn't remove the HTML tags, so you get a text message that looks like : "<html><body><h1>This Week's News</h1></body></html>" which is absolutely : not what is wanted.

You would probably need to take 3 passes at it or have a more complex
Regular Expression but you could replace </p> with 2 vbCrLf, <br> or <br /> with 1 vbCrLf and then use a regexp to remove all HTML tags. Actually any
block elements should be replaced with vbCrLf.

Something like this...

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

' converts HTML email to plain text

dim re, str, r
str = lcase("<HTML><HEAD><TITLE></TITLE></HEAD><BODY><p>Heading</p>line 1<br />line 2<br />line 3</BODY></HTML>")
str = replace(str,"<br />",vbCrLf)
str = replace(str,"</p>",vbCrLf & vbCrLf)
set re = new RegExp
re.Pattern = "<[^>]*>"
re.Global = true
re.IgnoreCase = true
r = re.replace(str,"")
Response.Write(r)
set re = nothing
%>

You can see it here but you need to view the source to see how it would turn out in an email.
http://kiddanger.com/lab/htmlx.asp

FYI.. My email is set to plain text. I get plain text but if it is HTML
formatted, then the HTML version is an attachment. I never see the HTML
code in my plain text message body.

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp MSDN Library - http://msdn.microsoft.com/library/default.asp

Jul 19 '05 #8
If you want tjust to remove the HTML Tags you could use
CDO.Message.AutoGenerateTextBody (never tried) :

http://msdn.microsoft.com/library/de...tetextbody.asp

--

"J. Alan Rueckgauer" <vo**@dev.nul> a écrit dans le message de
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello. I'm looking for a simple way to do the following:

We have a database that serves-up content to a website. Some of those items are events, some are news articles. They're stored in the DB as formatted
HTML so ASP just drops them right into a page shell.

Now, we want to send out a newsletter email containing some of those items. No problem sending as HTML. However, some of the members want just plain
text. Is there some magic method in CDO that can automatically convert HTML to plain text? Or, is there some existing VBScript code out there that can do this?

BTW, the environment is IIS 5.x (Windows 2000), Classic ASP, and CDO.

Thanks...

Jul 19 '05 #9


I am working on a vbscript subroutine that does just this. I am not
using CDO, so that would be something of a hack for me to use.

I don't think it is enough to remove the tags, and probably if the CDO
thing does work, it removes more than just the tags.

You should also remove the entire contents of the header, and probably
remove much of the white space you get after removing tags.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #10


CDO have such option which give u a choice to send either Text base or
html contents.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #11

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

Similar topics

5
by: lucanos | last post by:
Hey All, I'm having trouble trying to create a PHP file which will generate a multipart email message (containing both an HTML formatted part and a Plain Text formatted part). I have Googled...
3
by: Gene Ellis | last post by:
Hey everyone, I have a simple task. I want to take an XML file, pull out the elements in it, format them, and then send an html email based on it. What are the necessary steps? Any suggestions?...
8
by: LRW | last post by:
I'm not sure this message is totally appropriate for this group, so please, if anyone has a better group suggestion, let me know! My company sends out a monthly newsletter in HTML format to our...
5
by: Thierry | last post by:
Hello. Is it possible to send an email with some HTML code ? I tried the following code, where $msg == '<html><body>... blah blab blah etc.</body></html>' : // Adresse de l'expediteur...
0
by: nauticalmac | last post by:
I'm using CDO to send mail to the site owner from ASP pages with forms. Recently one of my forms is occasionally sending email with what seems to be an insertion which is replacing the plain text...
6
by: monomaniac21 | last post by:
hi all how can u send a plain text version of an email with the html so that the users mail client can access this plain text version? kind regards marc
0
by: jlconde | last post by:
I have a classe to send mails. It runs on yahoo well but with hotmail I never receive the mails.I do not receive an error neither. I would need some strange header to make the hotmail like my...
2
by: anu b | last post by:
Now i am sending email to my friend using session variable... but my code is as below private bool SendEmail(string email) { try
3
by: anu b | last post by:
Hii I am using System.net.mail for sending email... i need to send a webpage with its html content as my email body .....for that i used mail.Isbodyhtml as true...but it is not working for me...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.