Search code examples
asp.netauto-responder

How to Read HTML out of a webpage and use it as body of HTML Auto-Responder E-Mail


I am working on an HTML auto responder email. If there is a simpler way than what i am doing please let me know.

So far, i've built "pagename.aspx" and i read this page into a string variable, then use this variable as the BODY of the mail. This works.

The page optionally accepts a QueryString called "leadID". This is used to pull data from a database and populate fields on this page. This also works fine when i manually browse to the page - pagename.aspx?leadid=xyz

My Problem / Question is, how do i pass this querystring to the page and return the resulting HTML output of the page into a string , which can then be used as the body of my email.

Again, if there is a better way please let me know. I'm using LINQ to SQL, VB.NET and ASP.NET 3.5.

Thanks a million.


Solution

  • The easiest way is just to do a WebRequest to it:

    string url = "...";
    string result;
    
    HttpWebRequest webrequest = (HttpWebRequest) HttpWebRequest.Create(url);
    webrequest.Method        = "GET";
    webrequest.ContentLength = 0;
    
    WebResponse response = webrequest.GetResponse();
    
    using(StreamReader stream = new StreamReader(response.GetResponseStream())){
        result = stream.ReadToEnd();
    }