These are the steps to create a simple ASP.NET handler that returns a mailto: query string. You can use it to create a mailto: string dynamically and invoke a local email client.

At first, let's create a text file and call it MailTo.ashx. This file should contain only a single ASP.NET declaration:

<%@ WebHandler Language="C#" Class="WBS.TestApp.MailTo" %>

The MailTo.ashx file serves as a front-end for our handler. We will call it when we want to invoke the handler. The Class attribute is set to the fully qualified class name of the handler.

Next, let's create our handler class in a MailTo.cs file and derive it from IHttpHandler:

using System;
using System.Diagnostics;
using System.Web;

namespace WBS.TestApp
{
    public class MailTo : IHttpHandler
    {
        private string EmailSubject = "Hello";
        private string EmailBody = "This is a test.";
        private string EmailCC = "test\@email.com"; // provide a CC recipient email address here, if needed

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            // Uncomment for diagnostic info:
            // Debug.Trace("A mailto handler invoked (ProcessID: " + 
            //     Process.GetCurrentProcess().Id.ToString() + ")");

            string response = "?subject=" + Uri.EscapeDataString(EmailSubject) +
                "&body=" + EmailBody + "&cc=" + EmailCC;

            // Write the response string.
            context.Response.ContentType = "application/x-www-form-urlencoded";
            context.Response.Write(response);
        }
    }
}

Now, we need to test our handler. Let's create a web page Default.aspx with a single button:

<input type="button" value="Test Handler" onclick="javascript: InvokeEmailClient();" />

When we click the button a piece of JavaScript AJAX code invokes our handler and returns the mailto: query string "?subject=Hello%20Test&body=This is a test.&cc=This email address is being protected from spambots. You need JavaScript enabled to view it."

function InvokeEmailClient()
{
    var url = 'http://localhost:57776/MailTo.ashx'; // change the url to your environment
    client = null;
    client = new XMLHttpRequest();
    client.onreadystatechange =  HandleReadyStateChange;
    client.open('POST', url, true);         
    client.setRequestHeader('Content-type', 'text/plain');
    client.send();
}      

function HandleReadyStateChange()
{
    if (client.readyState == 4)
    {
        if (client.status == 200)
        {
            var msg = client.responseText;
            alert(msg);
        }
    }
}

Instead of showing the query string in an alert message box, you can invoke a local email client by replacing alert(msg) with the following line:

window.location = ('mailto:' + msg);

Some interesting information on ASP.NET handlers can also be found here: Debugging an HTTP handler.

That's all!