If you donβt need to redirect the page after rendering the contents of the page (from your sample code this doesnβt look like what you need), then you can use Response.Filter.
On top of my head, it looks something like this:
protected void Page_Load(object sender, System.EventArgs e) { Response.Filter = new SmtpFilter(Response.Filter); }
The SmtpFilter class is just a class that inherits from the Stream object.
The main method will be the Write method. Here is some code from my head to override the Write (...) method, send Smtp mail and continue processing.
public override void Write(byte[] buffer, int offset, int count) { // get the html string content= System.Text.Encoding.UTF8.GetString(buffer, offset, count); MailMessage mail = new MailMessage(); mail.From = new MailAddress(" test@test.com "); mail.To.Add(" steve@test.com "); mail.IsBodyHtml = true; mail.Subject = "Test"; mail.Body = content; SmtpClient smtp = new SmtpClient("1111"); smtp.Send(mail); buffer = System.Text.Encoding.UTF8.GetBytes(HTML); this.Base.Write(buffer, 0, buffer.Length); }
If you need more help with Response.Filters, you might want to google it. The first article I found was in VB.NET but is still useful:
http://aspnetlibrary.com/articledetails.aspx?article=Use-Response.Filter-to-intercept-your-HTML
source share