【问题标题】:Microsoft Outlook adding Hyperlink to Email C#Microsoft Outlook 将超链接添加到电子邮件 C#
【发布时间】:2011-09-10 05:07:10
【问题描述】:

使用 Microsoft Outlook 发送电子邮件时,我希望能够在电子邮件正文中发送文件位置和网站的超链接,我的代码中的正文是 oMsg.Body。任何帮助将不胜感激。

    private void button13_Click(object sender, EventArgs e)
    {
        //Send Routing and Drawing to Dan
        // Create the Outlook application by using inline initialization. 
        Outlook.Application oApp = new Outlook.Application();
        //Create the new message by using the simplest approach. 
        Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
        //Add a recipient
        Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("email-address here");
        oRecip.Resolve();
        //Set the basic properties. 
        oMsg.Subject = textBox1.Text + " Job Release";
        oMsg.Body = textBox1.Text + " is ready for release attached is the Print and Routing";
        //Send the message. 6
        oMsg.Send();
        //Explicitly release objects. 
        oRecip = null;
        oMsg = null;
        oApp = null;
        MessageBox.Show("Print and Routing Sent");
    }

【问题讨论】:

    标签: c# winforms outlook


    【解决方案1】:

    MSDN,看来您可以将BodyFormat 设置为olFormatHTML 并使用HTMLBody 属性:

    oMsg.BodyFormat = olFormatHTML; // <-- Probably dont need this
    oMsg.HTMLBody = "<HTML><BODY>Enter the message text here.</BODY></HTML>";
    

    HTMLBody 页面看来,如果您使用HTMLBody 属性,它会为您设置BodyFormat,因此您应该可以跳过设置它。

    【讨论】:

      【解决方案2】:

      使用 HTML 代替纯文本将允许您包含超链接的标记:

      oMsg.HTMLBody = "<html><body>";
      oMsg.HTMLBody += textBox1.Text + " is ready for release attached is the Print and Routing";
      oMsg.HTMLBody += "<p><a href='http://website.com'>Web Site</a></p></body></html>";
      

      编辑:将 Body 属性更改为 HTMLBody 属性。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-15
      • 2015-01-31
      • 2012-10-29
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      相关资源
      最近更新 更多