开发者

How to put a hyperlink into the email body using vb.net

What im trying to do is add a hyperlink to the body of an email in vb.net. What im getting when i send the email is the link is text. Here is what I doing so far below. Any help would be very much appreciated.开发者_如何学C

    '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)


You will need to enclose it in a tags.

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

And you need to set

email.IsBodyHtml = true


Try this:

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

The idea (I can't test it now, sorry) is you have to add not the url itself, but the HTML code used to create link.
Remember to set mail body to html with email.IsBodyHtml = True


I believe you need to set

IsBodyHtml = True

Then you can use plain HTML in the body of the e-mail. It's still up to the mail client to display it correctly. I've had a few cases where valid HTML that looked create in my browser was messy in my e-mail.


You haven't identified the body as HTML.

Add:

email.IsBodyHtml = true
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜