On Sun, 30 Jan 2005 19:40:53 +0100 in
microsoft.public.dotnet.framework.aspnet, "Olav Tollefsen" <x@y.com>
wrote:
I would like to generate a HTML page and mail it to a user. In order to
design the page, I would like to leverage the Web Form designer and
code-behind programming model, but instead of generating the page in
response to a browser request, I would like to generate the page from code
and fetch the HTML code into a string and use that as the mail body that I
send to a user by SMTP.
How can I do this?
Olav
Hi Olav,
You could probably use the WebClient class for this. Assuming you have
already designed a form called Mail.html with the designer, the
following code will instantiate the page on the server, and grab the
response. You can then convert it to a string, and email it out to
your clients.
using System.Net;
....
WebClient wc = new WebClient();
Byte[] pageData = wc.DownloadData("http://localhost/Mail.html");
string sHtml = Encoding.ASCII.GetString(pageData);
....
MailMessage Message = new MailMessage();
Message.Body = sHtml;
I hope that gets you started,
Roger