Microsoft Outlook将超链接添加到电子邮件C#

Rus*_*ari 5 c# outlook winforms

当使用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");
    }
Run Code Online (Sandbox Code Playgroud)

SwD*_*n81 7

MSDN,看起来你可以设置BodyFormatolFormatHTML并使用该HTMLBody属性:

oMsg.BodyFormat = olFormatHTML; // <-- Probably dont need this
oMsg.HTMLBody = "<HTML><BODY>Enter the message text here.</BODY></HTML>";
Run Code Online (Sandbox Code Playgroud)

HTMLBody页面中,BodyFormat如果您使用该HTMLBody属性,它看起来像是为您设置,因此您应该能够跳过设置它.

  • +1用于指出HTMLBody属性. (2认同)

Roc*_*oC5 5

使用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>";
Run Code Online (Sandbox Code Playgroud)

编辑:将Body财产更改为HTMLBody财产.