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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J. Alan Rueckgauer

    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...


  • Aaron [SQL Server MVP]

    #2
    Re: How? Send Same Email as HTML *or* Plain Text

    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.

    --
    Please contact this domain's administrator as their DNS Made Easy services have expired.

    (Reverse address to reply.)




    "J. Alan Rueckgauer" <void@dev.nul > wrote in message
    news:#TKr2cSWEH A.3120@TK2MSFTN GP12.phx.gbl...[color=blue]
    > 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[/color]
    items[color=blue]
    > 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[/color]
    items.[color=blue]
    > 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[/color]
    HTML[color=blue]
    > to plain text? Or, is there some existing VBScript code out there that[/color]
    can[color=blue]
    > do this?
    >
    > BTW, the environment is IIS 5.x (Windows 2000), Classic ASP, and CDO.
    >
    > Thanks...
    >
    >[/color]


    Comment

    • StephenMcC

      #3
      RE: How? Send Same Email as HTML *or* Plain Text

      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:
      [color=blue]
      > 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...
      >
      >
      >[/color]

      Comment

      • J. Alan Rueckgauer

        #4
        Re: How? Send Same Email as HTML *or* Plain Text


        "Aaron [SQL Server MVP]" <ten.xoc@dnartr eb.noraa> wrote in message
        news:eqaJfoSWEH A.1760@TK2MSFTN GP10.phx.gbl...[color=blue]
        > 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.[/color]
        [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


        Comment

        • Aaron [SQL Server MVP]

          #5
          Re: How? Send Same Email as HTML *or* Plain Text

          > 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).

          --
          Please contact this domain's administrator as their DNS Made Easy services have expired.

          (Reverse address to reply.)


          Comment

          • J. Alan Rueckgauer

            #6
            Re: How? Send Same Email as HTML *or* Plain Text


            "StephenMcC " <StephenMcC@dis cussions.micros oft.com> wrote in message
            news:61A8E251-B10C-4F0E-9D39-2F309115B2AD@mi crosoft.com...[color=blue]
            > If ur using CDO-NTS maybe have a look at HTMLText/Text properties of the[/color]
            Message object, using which depending on how recipient wishes to receive
            emails!?[color=blue]
            >[/color]
            [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><h 1>This Week's News</h1></body></html>" which is absolutely
            not what is wanted.


            Comment

            • Roland Hall

              #7
              Re: How? Send Same Email as HTML *or* Plain Text

              "J. Alan Rueckgauer" wrote in message
              news:Od977ySWEH A.3664@TK2MSFTN GP12.phx.gbl...

              : "StephenMcC " <StephenMcC@dis cussions.micros oft.com> wrote in message
              : news:61A8E251-B10C-4F0E-9D39-2F309115B2AD@mi crosoft.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><h 1>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=VBScri pt %>
              <%
              Option Explicit
              Response.Buffer = True

              ' converts HTML email to plain text

              dim re, str, r
              str = lcase("<HTML><H EAD><TITLE></TITLE></HEAD><BODY><p>H eading</p>line 1<br
              />line 2<br />line 3</BODY></HTML>")
              str = replace(str,"<b r />",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.


              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


              Comment

              • Aaron [SQL Server MVP]

                #8
                Re: How? Send Same Email as HTML *or* Plain Text

                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>

                --
                Please contact this domain's administrator as their DNS Made Easy services have expired.

                (Reverse address to reply.)




                "Roland Hall" <nobody@nowhere > wrote in message
                news:OZVph7aWEH A.1152@TK2MSFTN GP09.phx.gbl...[color=blue]
                > "J. Alan Rueckgauer" wrote in message
                > news:Od977ySWEH A.3664@TK2MSFTN GP12.phx.gbl...
                >
                > : "StephenMcC " <StephenMcC@dis cussions.micros oft.com> wrote in message
                > : news:61A8E251-B10C-4F0E-9D39-2F309115B2AD@mi crosoft.com...
                > : > If ur using CDO-NTS maybe have a look at HTMLText/Text properties of[/color]
                the[color=blue]
                > : 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[/color]
                HTML,[color=blue]
                > : 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[/color]
                like[color=blue]
                > : "<html><body><h 1>This Week's News</h1></body></html>" which is[/color]
                absolutely[color=blue]
                > : 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[/color]
                />[color=blue]
                > 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=VBScri pt %>
                > <%
                > Option Explicit
                > Response.Buffer = True
                >
                > ' converts HTML email to plain text
                >
                > dim re, str, r
                > str = lcase("<HTML><H EAD><TITLE></TITLE></HEAD><BODY><p>H eading</p>line[/color]
                1<br[color=blue]
                > />line 2<br />line 3</BODY></HTML>")
                > str = replace(str,"<b r />",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[/color]
                turn[color=blue]
                > 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 -[/color]
                http://msdn.microsoft.com/downloads/list/webdev.asp[color=blue]
                > MSDN Library - http://msdn.microsoft.com/library/default.asp
                >
                >[/color]


                Comment

                • Patrice

                  #9
                  Re: How? Send Same Email as HTML *or* Plain Text

                  If you want tjust to remove the HTML Tags you could use
                  CDO.Message.Aut oGenerateTextBo dy (never tried) :



                  --

                  "J. Alan Rueckgauer" <void@dev.nul > a écrit dans le message de
                  news:%23TKr2cSW EHA.3120@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                  > 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[/color]
                  items[color=blue]
                  > 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[/color]
                  items.[color=blue]
                  > 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[/color]
                  HTML[color=blue]
                  > to plain text? Or, is there some existing VBScript code out there that[/color]
                  can[color=blue]
                  > do this?
                  >
                  > BTW, the environment is IIS 5.x (Windows 2000), Classic ASP, and CDO.
                  >
                  > Thanks...
                  >
                  >[/color]


                  Comment

                  • Nick

                    #10
                    Re: How? Send Same Email as HTML *or* Plain Text



                    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!

                    Comment

                    • Devdex Developer

                      #11
                      Re: How? Send Same Email as HTML *or* Plain Text



                      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!

                      Comment

                      Working...