开发者

Hyperlink an Email Address using LinkLabel in C#

I have made an about box that is meant to allow users to clic开发者_如何学编程k 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


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");


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();
}


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);


<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.


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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜