Results 1 to 2 of 2

Thread: Send rendered page as mail

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Location
    india
    Posts
    95

    Send rendered page as mail

    hi,

    i need some idea about sending the rendered page (.aspx) content as mail body. I have tried the rendercontrl method for each control and some stringbuilder to construct the HTML content. But this is very tedious if i change the .aspx page content to be displayed.

    thanking u

    v.r.mahendran

  2. #2
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: Send rendered page as mail

    OK this sin't perfect but it does work. It should give you a good start anyway.
    VB Code:
    1. <%@ Page Language="VB" %>
    2. <%@ import Namespace="System.IO" %>
    3. <%@ import Namespace="System.Net" %>
    4. <%@ import Namespace="System.Web.Mail" %>
    5. <script runat="server">
    6.  
    7.     Dim strMailBody as String
    8.  
    9.     Private Sub GetHTML()
    10.         Dim strmReader As StreamReader = Nothing
    11.         Dim StrURL As String = "http://blogs.msdn.com/lisawoll/"
    12.  
    13.         Dim objRequest As WebRequest = WebRequest.Create(StrURL)
    14.         Dim objResponse As WebResponse = objRequest.GetResponse()
    15.  
    16.         strmReader = New StreamReader(objResponse.GetResponseStream())
    17.  
    18.         Dim strContent As String = strmReader.ReadToEnd()
    19.         Dim RegEx As Regex = _
    20.             New Regex("<HTML>((.|\n)*?)</HTML>", _
    21.             RegexOptions.IgnoreCase)
    22.  
    23.         Dim getMatch As Match = RegEx.Match(strContent)
    24.         strMailBody = (getMatch.Value)
    25.  
    26.         Dim email As New MailMessage
    27.  
    28.         With email
    29.             .To = txtTo.Text
    30.             .From = txtFrom.Text
    31.             .Body = strMailBody
    32.             .Subject = txtSubject.Text
    33.             .BodyFormat = MailFormat.HTML
    34.         End With
    35.  
    36.         smtpMail.SmtpServer() = txtMserver.Text
    37.         SmtpMail.Send(email)
    38.  
    39.     End Sub
    40.  
    41.     Private Sub Button1_Click(s As Object, e As EventArgs)
    42.         GetHTML()
    43.     End Sub
    44.  
    45. </script>
    Last edited by BukHix; Apr 19th, 2005 at 03:53 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width