title: Can I set up HTML/Email Templates with ASP.NET?
body: <p>I'm working on a site that will send out a significant number of emails. I want to set up both header and footer text, or maybe even templates to allow the users to easily edit these emails if they need to.</p>
  
  <p>If I embed the HTML inside C# string literals, it's ugly and they would have to worry about escaping.  Including flat files for the header and footer might work, but something about it just doesn't feel right.</p>
  
  <p>What would be ideal what be to use a <code>.ASPX</code> page as a template somehow, then just tell my code to serve that page, and use the HTML returned for the email.</p>
  
  <p>Is there a nice and easy way to do this? Is there a better way to go about solving this problem?</p>
  
  <p><strong>Updated:</strong><br>
  I added an answer that enables you to use a standard .aspx page as the email template.  Just replace all the variables like you normally would, use databinding, etc.  Then just capture the output of the page, and voila!  You have your HTML email!</p>
  
  <p><strong>UPDATED WITH CAVEAT!!!:</strong><br>
  I was using the MailDefinition class on some aspx pages just fine, but when trying to use this class during a server process that was running, it failed.  I believe it was because the MailDefinition.CreateMailMessage() method requires a valid control to reference, even though it doesn't always do something.  Because of this, I would recommend my approach using an aspx page, or Mun's approach using an ascx page, which seems a little better.</p>