19

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

shA.t
  • 16,580
  • 5
  • 54
  • 111
Chris Bacon
  • 995
  • 8
  • 30
  • 42

5 Answers5

39

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:youremail@xx.com");
Ozzy
  • 1,712
  • 11
  • 14
  • 9
    It's worth noting here that if the user doesn't have a default mail-client set up in Win XP/7 this call will throw an exception `System.ComponentModel.Win32Exception (0x80004005): No application is associated with the specified file for this operation`. Win 8 will at least ask them what app they wish to launch the "mailto" handler with – Xerxes Feb 07 '13 at 01:23
  • @Xerxes , how do we avoid this error or can we catch it and ask for which app to launch? – indago Aug 09 '15 at 15:44
6

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:someone@somewhere.com?subject=hello&body=love my body";
    proc.Start();
}
Community
  • 1
  • 1
3

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

linkLabel1.Links.Add(new LinkLabel.Link(0, linkLabel1.Text.Length, "mailto:bob@someaddress.com"));

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);
KyleMit
  • 30,350
  • 66
  • 462
  • 664
miyamotogL
  • 513
  • 3
  • 10
2

<a href="mailto:bob@someaddress.com"></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 bob@someadress.com) in the click event handler.

DancesWithBamboo
  • 4,176
  • 1
  • 19
  • 20
2

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:info@cybersprocket.com");
}

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");
}
Lance Cleveland
  • 3,098
  • 1
  • 33
  • 36