title: How do I properly encode a mailto link?
body: <p>I am generating some HTML and I want to generate an XSS- and database-content-safe <code>mailto</code> link.  What is the proper encoding to use here?  How's this?</p>
  
  <pre><code>myLiteral.Text = string.Format(
    "mailto:{0}?Content-Type=text/html&amp;amp;Subject={1}&amp;amp;body={2}", 
    HttpUtility.UrlEncode(email_address),
    HttpUtility.UrlEncode(subject),
    HttpUtility.UrlEncode(body_message));
  </code></pre>
  
  <p>Should I use <code>UrlEncode</code> here?  <code>HtmlEncode</code>?  Do what I did, then <code>HtmlEncode</code> the entirety?  I'm writing HTML of a URL, so I'm a little unclear...</p>
  
  <p>@Quentin, is this what you're describing?  (Changed <code>&amp;amp;</code>s to <code>&amp;</code> since I'm about to <code>HtmlEncode</code>...)</p>
  
  <pre><code>myLiteral.Text = 
    HttpUtility.HtmlEncode(HttpUtility.UrlEncode(
      string.Format(
        "mailto:{0}?Content-Type=text/html&amp;Subject={1}&amp;body={2}", 
        email_address, subject, body_message)));
  </code></pre>