In this article I will explain the different ways to create MailTo Link in ASP.Net.
MailTo links are used to open the default email client application present on the user’s machine in ASP.Net.
Generally we associate mailto with a hyperlink but we can also associate it with a Button or Image and also open the mailto email window using from server side event.
 
 
MailTo using HTML Anchor element
Below is the simplest way to create a MailTo using HTML Anchor element.
<a href = "mailto:abc@abc.com">abc@abc.com</a>
 
 
MailTo using ASP.Net HyperLink Control
The following describes how to use ASP.Net HyperLink to create a MailTo link.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl = "mailto:abc@abc.com" Text = "abc@abc.com"></asp:HyperLink>
 
 
MailTo using HTML Image element
In order to create MailTo link using image there are two ways: -
1. Using HTML Link
<a href = "mailto:abc@abc.com"><img src = "images/img.jpg" /></a>
 
2. Using JavaScript
<img src = "images/img.jpg" onclick = "parent.location='mailto:abc@abc.com'"
style ="cursor:pointer" />
 
 
 
MailTo using HTML Button element
 
In order to open the default email client on HTML Button click, you will need to set the JavaScript parent.location property to the MailTo link.
 
<input id="Button1" type="button" value="button"
onclick = "parent.location='mailto:abc@abc.com'" />
 
 
Implement MailTo link to open Default email client from Server Side in ASP.Net
Following HTML Markup consists of an ASP.Net Button with a Server Side click event handler.
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
When the Button is clicked, a Client side JavaScript is registered, which sets the JavaScript parent.location property to the MailTo link.
 
C#
protected void Button1_Click(object sender, EventArgs e)
{
        string email = "abc@abc.com";
    ClientScript.RegisterStartupScript(this.GetType(), "mailto", "parent.location='mailto:" + email + "'", true);
}
 
VB.Net
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim email As String = "abc@abc.com"
    ClientScript.RegisterStartupScript(Me.GetType(), "mailto", "parent.location='mailto:" & email & "'", True)
End Sub
 
 
Screenshot
Open Defaullt Email (Mail) Client application in ASP.Net
 
 
Browser Compatibility
The above code has been tested in the following browsers.
Internet Explorer  FireFox  Chrome  Safari  Opera 
* All browser logos displayed above are property of their respective owners.