Chris Bacon
Chris Bacon

Reputation: 1003

Hyperlink an Email Address using LinkLabel in C#

I have made an about box that is meant to allow users to click the hyperlink email address which will take them to a Microsoft Outlook to be able to send an email to the email address, but I don't know how to link it to Outlook and allow the user to click the link to do this

Upvotes: 19

Views: 47452

Answers (5)

miyamotogL
miyamotogL

Reputation: 513

Add a LinkLabel like this in the form's constructor:

linkLabel1.Links.Add(new LinkLabel.Link(0, linkLabel1.Text.Length, "mailto:[email protected]"));

Then, in the LinkLabel's click handler:

linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited = true;
string target = e.Link.LinkData as string;
System.Diagnostics.Process.Start(target);

Upvotes: 3

Lance Cleveland
Lance Cleveland

Reputation: 3204

Put a link label on your form.

Double-click the link-label to create your on click handler then put the system process call in it like this:

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    linkLabel1.LinkVisited = true;
    System.Diagnostics.Process.Start("mailto:[email protected]");
}

That will fire off the default email application that the user has configured on their windows box.

Replace the mailto: with a HTTP reference to open a web page in their default browser:

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    linkLabel1.LinkVisited = true;
    System.Diagnostics.Process.Start("http://www.cybersprocket.com");
}

Upvotes: 2

user1921
user1921

Reputation:

Check this SO thread:

How to send email using default email client?

Basically, the click event would be something like this:

private void linkLabel1_LinkClicked(object sender,System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
 System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo.FileName = "mailto:[email protected]?subject=hello&body=love my body";
    proc.Start();
}

Upvotes: 6

DancesWithBamboo
DancesWithBamboo

Reputation: 4156

<a href="mailto:[email protected]"></a>.

If outlook is installed on the user's machine it will use it.

Edit: oops just noticed you wanted Winforms not web.

For winforms use System.Diagnositcs.Process.Start(outlook.exe /c ipm.note /m [email protected]) in the click event handler.

Upvotes: 2

Ozzy
Ozzy

Reputation: 1730

You are not saying whether you are using Win- or WebForms...in WinForms I think you need to create an event-handler for the click event. Inside that you can start the default mail application by typing:

System.Diagnostics.Process.Start("mailto:[email protected]");

Upvotes: 40

Related Questions