View Single Post
  #1 (permalink)  
Old November 19th, 2008, 10:21 AM
hdpark hdpark is offline
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>