Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 19th, 2008, 10:21 AM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to show plain format from html

Hi Imar,

From your Webshop's SendConfirmationMessage is working great in html format. I need to send email in plain format, not html. How can I do it?

Your kind advice would be appreciated.
HD


Public Shared Function GetHtmlFromControl(ByVal theControl As WebControl) As String
        Dim myStringBuilder As StringBuilder = New StringBuilder()
        Dim myStringWriter As System.IO.StringWriter = _
              New IO.StringWriter(myStringBuilder)
        Dim myHtmlTextWriter As HtmlTextWriter = New HtmlTextWriter(myStringWriter)
        theControl.RenderControl(myHtmlTextWriter)
        Return myStringBuilder.ToString()
    End Function
    Public Shared Sub SendConfirmationMessage( _
        ByVal theShoppingCart As ShoppingCart, ByVal orderId As Integer, _
        ByVal userName As String, ByVal emailAddress As String)

        Try
            Dim myGridView As GridView = CreateGridView()
            myGridView.DataSource = theShoppingCart.Items
            myGridView.DataBind()

            If myGridView.Rows.Count > 0 Then
                myGridView.FooterRow.Cells(0).Text = "Totals:"
                myGridView.FooterRow.Cells(3).Text = String.Format("{0:c}", theShoppingCart.Total)

                Dim theSubject As String = "Your order at Sports Camps"
                Dim theMessage As String = My.Computer.FileSystem.ReadAllText _
                  (AppConfiguration.ConfirmationMessageLocation)

                Dim mySmtpClient As New System.Net.Mail.SmtpClient
                theMessage = theMessage.Replace("##ShoppingCart##", GetHtmlFromControl(myGridView))
                theMessage = theMessage.Replace("##OrderNumber##", orderId.ToString())
                mySmtpClient.Send("hdpark@myemail.com", emailAddress, theSubject, theMessage)
            End If
        Catch ex As Exception
        End Try
    End Sub

--------
ConfirmationMessage.txt:
<html>
<head>
  <title>Your Order at Sports Camps WebShop</title>
</head>
<body>
  Dear customer,<br /><br />
  Thank you for your order at Sports Camps WebShop. Your order number is
          <b>##OrderNumber##</b><br /><br />
  Below you find a list of the products you have ordered. The goods will ship as
  soon as we receive your payment.<br /><br />
  ##ShoppingCart##
  <br /><br />
  Thanks<br /><br />
  The Sports Camps WebShop Team
</body>
</html>

  #2 (permalink)  
Old November 19th, 2008, 04:06 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You can construct a MailMessage instance, set the Body to your plain text and IsBodyHtml to False and then send the message using the Send method of the mail client.

http://msdn.microsoft.com/en-us/libr...ilmessage.aspx

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old November 20th, 2008, 12:16 AM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I cannot understand your advice.
Would you please explain more?

Thanks,
HD

  #4 (permalink)  
Old November 20th, 2008, 04:25 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Did you look at the links I posted? You'll find example code in them:

Dim message As MailMessage = new MailMessage(
               "jane@contoso.com",
               "ben@contoso.com",
               "Quarterly data report.",
               "Plain text here.")
' optionally, set properties on message here:

' message.Body = "Plain Text Boxy" ' not necessary as it has been set in the constructor
' message.To.Add(other recipients go here)
' message.IsBodyHtml = False

Dim mySmtpClient As New System.Net.Mail.SmtpClient
mySmtpClient.Send(message)

This creates a new message, sets To, Fro, Subject and Body in the constructor and uses the SmtpClient to send it.

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #5 (permalink)  
Old November 20th, 2008, 04:12 PM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I think it's off from my intention. My intention is at following red line.
Thanks,
HD

Dim mySmtpClient As New System.Net.Mail.SmtpClient
theMessage = theMessage.Replace("##ShoppingCart##", GetHtmlFromControl(myGridView))
theMessage = theMessage.Replace("##OrderNumber##", orderId.ToString())

===> Is there any way to convert html formatted message(theMessage) to plain text? <====

mySmtpClient.Send("hdpark@myemail.com", emailAddress, theSubject, theMessage)


  #6 (permalink)  
Old November 20th, 2008, 07:03 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I am not sure I understand what you're asking. The mail template is in HTML, so if you need plain text, why don't you change the HTML in the mail template to plain text?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #7 (permalink)  
Old November 24th, 2008, 04:29 PM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

When I email it in html format, it displays like following #A. How can I make recipient see it in email like in internet html format?

Thanks,
HD

#A:
<html>
<head>
<title>Your Order at Sports Camps WebShop</title>
</head>
<body>
Dear customer,<br /><br />
Thank you for your order at Sports Camps WebShop. Your order number is
         <b>1023</b><br /><br />
Below you find a list of the products you have ordered. The goods will ship as
soon as we receive your payment.<br /><br />
<div>
    <table cellspacing="0" rules="all" border="1" style="border-width:1px;border-style:solid;width:100%;border-collapse:collapse;">
        <tr align="left" style="color:White;background-color:#ffb49f;font-family:Arial;">
            <th scope="col">Title</th><th scope="col">Quantity</th><th scope="col">Price</th><th scope="col">Total</th>
        </tr><tr style="color:Black;background-color:White;font-family:Arial;">
            <td>TURP000_A</td><td align="right">1</td><td align="right">$0.17</td><td align="right">$0.17</td>
        </tr><tr style="font-family:Arial;font-weight:bold;">
            <td>Totals:</td><td>&nbsp;</td><td>&nbsp;</td><td align="right">$0.17</td>
        </tr>
    </table>
</div>
<br /><br />
Thanks<br /><br />
The Sports Camps WebShop Team
</body>
</html>
  #8 (permalink)  
Old November 24th, 2008, 05:04 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Now you want it in HTML format? I thought you wanted it as plain text? Sorry, but I lost you....

Can you explain - in full detail - what it is that you need, and what you already have? Otherwise, I can't help much.

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #9 (permalink)  
Old November 25th, 2008, 09:58 AM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Imar for your kind understanding even if I made you confuse.
1. My problem is : When I email it, it displays in html code format(following #A).
2. My goal is : How can I make it display in web browser format(following #B), not code style format(following #A).
Your kind advice would be kindly appreciated.

#A code style format :
<html>
<head>
  <title>Your Order at Sports Camps WebShop</title>
</head>
<body>
  Dear customer,<br /><br />
  Thank you for your order at Sports Camps WebShop. Your order number is
          <b>1023</b><br /><br />
  Below you find a list of the products you have ordered. The goods will ship as
  soon as we receive your payment.<br /><br />
  <div>
    <table cellspacing="0" rules="all" border="1" style="border-width:1px;border-style:solid;width:100%;border-collapse:collapse;">
        <tr align="left" style="color:White;background-color:#ffb49f;font-family:Arial;">
            <th scope="col">Title</th><th scope="col">Quantity</th><th scope="col">Price</th><th scope="col">Total</th>
        </tr><tr style="color:Black;background-color:White;font-family:Arial;">
            <td>TURP000_A</td><td align="right">1</td><td align="right">$0.17</td><td align="right">$0.17</td>
        </tr><tr style="font-family:Arial;font-weight:bold;">
            <td>Totals:</td><td>?lt;/td><td>?lt;/td><td align="right">$0.17</td>
        </tr>
    </table>
</div>
  <br /><br />
  Thanks<br /><br />
  The Sports Camps WebShop Team
</body>
</html

#B web browser format:
Dear customer,

Thank you for your order at Sports Camps WebShop. Your order number is 1023

Below you find a list of the products you have ordered. The goods will ship as soon as we receive your payment.

table data display with border(I cannot put it here).

Thanks

The Sports Camps WebShop Team



  #10 (permalink)  
Old November 25th, 2008, 12:13 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

In that case, you should be able to do it the way you;re doing it now.

Here's how it works:

1. Create a Body that contains HTML

2. Set IsBodyHtml to true

If the text ends up looking like HTML, rather than the visual representation of it, you have a mail client that does not support HTML.

What client are you using?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent - Send mail with plain view and html view ashish.dadhwal ASP.NET 2.0 Professional 0 November 27th, 2008 01:49 AM
Show Tree Format data rajasarkar ASP.NET 1.0 and 1.1 Professional 0 July 5th, 2006 02:59 AM
plain vs HTML format juergreh Beginning PHP 2 April 19th, 2005 08:42 AM



All times are GMT -4. The time now is 08:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.