views:

40

answers:

4

To be specific, here is what I am doing, and here is what I am trying to do:

I'm coding an ASP.NET page, with VB code behind. When the user clicks a button on the page, I send them an email with information and instructions. Rather than sending a plain text email, I send a nice, pretty, HTML-formatted one. Right now, I'm doing this in a way that I KNOW will be difficult to maintain. That is, I'm straight up writing out all of the html. i.e.

    markup += "<fieldset>"

    markup += "<legend>"
    markup += "Required Documents"
    markup += "</legend>"

...and so on. Is there a way to create an aspx page (with vb code behind), and send the html of that page in the body of the email? The information is dynamic, so this pseudo-page would need logic in the on-load event to format the html correctly.

Thanks!

A: 

This one should help you get there:

How to save current aspx page as html

Leniel Macaferi
That did it. The page looks sort of crappy in email format, but that's nothing a few querystrings and formatting functions won't fix. Thanks!
Ryan
Great to know it helped you... :)
Leniel Macaferi
+1  A: 
WebClient client = new WebClient ();
string html = client.DownloadString("http://domain.com/emailtemplate.aspx?id=1");
jessegavin
This pulled the straight ASP code...didn't go through the HTML generation part.
Ryan
Wow. that is surprising. I will have to take a look at that. I would have figured that the web server would treat it like a normal http request.
jessegavin
A: 

If you have access to a database you can always drop the html in there otherwise, I solved this problem by creating a mailtemplate.html file with [replace] sections in it so all you have to do is read the file into a string object do your replaces and then send it out.

If you have to you can maintain multiple templates this way. I use it mostly as a wrapper on emails my systems need to send out so my template has a [body] tag in it that gets replaced with whatever message I need to send. I have also used this method to wrap multiple files into a single email output.

Varuuknahl
A: 

I assume you want to build the html on the fly... One (certainly the most maintainable) solution is to build a template based system.

Technically you maintain your html (e.g. email shots) in a directory read the templates from your ASP.NET program, fill in the details and send the html mail to the user.

G Berdal