 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 19th, 2008, 10:21 AM
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|

November 19th, 2008, 04:06 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|

November 20th, 2008, 12:16 AM
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
I cannot understand your advice.
Would you please explain more?
Thanks,
HD
|

November 20th, 2008, 04:25 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|

November 20th, 2008, 04:12 PM
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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)
|

November 24th, 2008, 04:29 PM
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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> </td><td> </td><td align="right">$0.17</td>
</tr>
</table>
</div>
<br /><br />
Thanks<br /><br />
The Sports Camps WebShop Team
</body>
</html>
|

November 24th, 2008, 05:04 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|

November 25th, 2008, 09:58 AM
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

November 25th, 2008, 12:13 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|
 |