【问题标题】:Hyperlink an Email Address using LinkLabel in C#在 C# 中使用 LinkLabel 超链接电子邮件地址
【发布时间】:2011-05-14 18:11:41
【问题描述】:

我已经制作了一个关于框,旨在允许用户单击超链接电子邮件地址,这将把他们带到 Microsoft Outlook 以便能够向该电子邮件地址发送电子邮件,但我不知道如何链接它到 Outlook 并允许用户单击链接来执行此操作

【问题讨论】:

    标签: c# email hyperlink outlook linklabel


    【解决方案1】:

    您并不是说您使用的是 WinForms 还是 WebForms...在 WinForms 中,我认为您需要为 click 事件创建一个事件处理程序。在里面,您可以通过键入以下内容启动默认邮件应用程序:

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

    【讨论】:

    • 这里值得注意的是,如果用户没有在 Win XP/7 中设置默认邮件客户端,此调用将引发异常 System.ComponentModel.Win32Exception (0x80004005): No application is associated with the specified file for this operation。 Win 8 至少会询问他们希望使用什么应用来启动“mailto”处理程序
    • @Xerxes ,我们如何避免这个错误,或者我们可以抓住它并询问要启动哪个应用程序?
    【解决方案2】:

    检查这个 SO 线程:

    How to send email using default email client?

    基本上,点击事件是这样的:

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

    【讨论】:

      【解决方案3】:

      在表单的构造函数中像这样添加LinkLabel

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

      然后,在LinkLabel 的点击处理程序中:

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

      【讨论】:

        【解决方案4】:

        <a href="mailto:bob@someaddress.com"></a>.

        如果用户的机器上安装了 Outlook,它将使用它。

        编辑:哎呀刚刚注意到你想要 Winforms 而不是 web。

        对于winforms,在点击事件处理程序中使用System.Diagnositcs.Process.Start(outlook.exe /c ipm.note /m bob@someadress.com)

        【讨论】:

          【解决方案5】:

          在您的表单上放置一个链接标签。

          双击链接标签以创建您的点击处理程序,然后将系统进程调用放入其中,如下所示:

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

          这将触发用户在其 Windows 框中配置的默认电子邮件应用程序。

          将 mailto: 替换为 HTTP 引用以在默认浏览器中打开网页:

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

          【讨论】:

            猜你喜欢
            • 2013-08-03
            • 2015-01-12
            • 2013-11-25
            • 2011-10-01
            • 1970-01-01
            • 2011-06-04
            • 2019-03-11
            • 1970-01-01
            相关资源
            最近更新 更多