简体   繁体   English

使用C#中的LinkLabel超链接电子邮件地址

[英]Hyperlink an Email Address using LinkLabel in C#

我做了一个关于框的意思是允许用户点击超链接电子邮件地址,这将把他们带到Microsoft Outlook,以便能够向电子邮件地址发送电子邮件,但我不知道如何将其链接到Outlook并允许用户单击链接以执行此操作

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. 你不是说你是在WinForms中使用Win或WebForms ......我认为你需要为click事件创建一个事件处理程序。 Inside that you can start the default mail application by typing: 在里面你可以输入以下内容来启动默认邮件应用程序:

System.Diagnostics.Process.Start("mailto:youremail@xx.com");

Check this SO thread: 检查这个SO线程:

How to send email using default email client? 如何使用默认电子邮件客户端发送邮件?

Basically, the click event would be something like this: 基本上,click事件将是这样的:

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: 在表单的构造函数中添加这样的LinkLabel

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

Then, in the LinkLabel 's click handler: 然后,在LinkLabel的点击处理程序中:

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. 如果在用户的机器上安装了outlook,它将使用它。

Edit: oops just noticed you wanted Winforms not web. 编辑:oops只是注意到你想要Winforms而不是web。

For winforms use System.Diagnositcs.Process.Start(outlook.exe /c ipm.note /m bob@someadress.com) in the click event handler. 对于winforms,在click事件处理程序中使用System.Diagnositcs.Process.Start(outlook.exe /c ipm.note /m bob@someadress.com)

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: 双击链接标签以创建on click处理程序,然后将系统进程调用放入其中,如下所示:

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. 这将触发用户在其Windows框中配置的默认电子邮件应用程序。

Replace the mailto: with a HTTP reference to open a web page in their default browser: 将mailto:替换为HTTP引用,以在其默认浏览器中打开网页:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM