如何使用vb.net将超链接放入电子邮件正文

如何使用vb.net将超链接放入电子邮件正文,vb.net,Vb.net,我想做的是在vb.net中给邮件正文添加一个超链接。当我发送电子邮件时,我得到的是文本链接。下面是我到目前为止所做的。任何帮助都将不胜感激 'Accepts two parameters - the username and password for the email client Dim credentials As New System.Net.NetworkCredential("test@test.net", "test") smtpClient.Creden

我想做的是在vb.net中给邮件正文添加一个超链接。当我发送电子邮件时,我得到的是文本链接。下面是我到目前为止所做的。任何帮助都将不胜感激

    'Accepts two parameters - the username and password for the email client
    Dim credentials As New System.Net.NetworkCredential("test@test.net", "test")

    smtpClient.Credentials = credentials
    Dim body, link As String

    link = "http://localhost:" & partUrl & "/test.aspx?autoNum=" & autoNum
    body = "Test email." & "<br/><br/>"

    body += link

    Dim email As New MailMessage
    email.From = New MailAddress("test@test.net")
    email.Body = body
    email.Subject = "test Change/Request Password"
    email.To.Add(New MailAddress(toAddress))

    smtpClient.Send(email)
”接受两个参数—电子邮件客户端的用户名和密码
Dim凭据作为新的System.Net.NetworkCredential(“test@test.net“,“测试”)
smtpClient.Credentials=凭据
暗体,链接为字符串
链接=”http://localhost:“&partUrl&”/test.aspx?autoNum=“&autoNum
body=“测试电子邮件。”&“

” body+=链接 将电子邮件设置为新邮件消息 email.From=新邮件地址(“test@test.net") email.Body=Body email.Subject=“测试更改/请求密码” email.To.Add(新邮件地址(toAddress)) smtpClient.Send(电子邮件)
试试这个:

link = "<a href=""http://localhost:" & partUrl & "/test.aspx?autoNum=" & autoNum & """>Link</a>"
body = "Test email." & "<br/><br/>"
body += link
link=“”
body=“测试电子邮件。”&“

” body+=链接
这个想法(对不起,我现在无法测试)是您必须添加的不是url本身,而是用于创建链接的HTML代码。

记得用
email.IsBodyHtml=True将邮件正文设置为html

我相信您需要设置

IsBodyHtml = True

然后可以在电子邮件正文中使用普通HTML。邮件客户端仍然需要正确显示它。我曾经遇到过一些情况,在我的浏览器中创建的有效HTML在我的电子邮件中看起来很凌乱。

您还没有将正文标识为HTML

加:


您需要将其封装在标签中

link = "<a href=""http://localhost:" & partUrl & "/test.aspx?autoNum=" & autoNum & """>Click here</a>"
link = "<a href=""http://localhost:" & partUrl & "/test.aspx?autoNum=" & autoNum & """>Click here</a>"
email.IsBodyHtml = true