Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using stringreader to set email body to html page

Status
Not open for further replies.

arkadia93

Programmer
Oct 19, 2006
110
GB
I am trying to send out an email that is based upon an HTML page. Is it possible to read the HTML page into something like a StringReader and then set the Mail.Body equal to the StringReader? If it is, does anybody have any code samples?
 
You can create a httpWebRequest to create a connection to the page, then read the response into a string with the httpWebResponse class.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
As with any other class/method, have a look at it's associated help file. You'll find that this type of information is available from Microsoft on pretty much all of the framework so a simple search or google should always be carried out first.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Would I be right doing something like this?

message.IsBodyHtml = true;

//Message body content
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("
//then read the response into a string with the httpWebResponse class
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();

message.Body = HttpWResp;
 
You can't set the Body property to a class as it is expecting a String.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I've found an alternative way of doing this which seems to work :

message.IsBodyHtml = true;

StreamReader sr = new StreamReader(Server.MapPath("referred_email.html"));
string s = sr.ReadToEnd();

message.Body = s;
 
Yes, that will work as long as the file is always based locally. The other method will work if the file is available from any web server.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top