email hyperlink in MailMessage
I'm using the following as part of sending a .net 4 email. I'd like to show the reply to text as an email hyperlink but can't quite get the format correct.
nMail.Body = Description " + txtdescriptio开发者_StackOverflow中文版n.Text +
"<br />Reply to (click here):" + txtemail.Text);
Wrap the address in an anchor tag <a>
to make a link. Also make sure you encode the input.
Use HttpUtility.HtmlEncode
on text and Uri.EscapeUriString
on links.
nMail.Body = "Description " +
HttpUtility.HtmlEncode(txtdescription.Text) +
"<br />Reply to <a href=\"mailto:" +
Uri.EscapeUriString(txtemail.Text) +
"\">" +
HttpUtility.HtmlEncode(txtemail.Text) +
"</a>");
Use the following if the e-mail address is contained in txtemail.Text. Remember to first validate the content of txtemail.Text. The output of the following is a hyperlink to an e-mail address that also contains the e-mail address as the hyperlink text.
nMail.Body = "Description " + txtdescription.Text + "<br />Reply to (click here): " + "<a href='mailto:" + txtemail.Text + "'>" + txtemail.Text + "</a>");
You can write <a href='mailto:username@example.com'>Link Text</a>
.
Try this
private string BuildEmailText(string description, string replyToAddress, string replyToText)
{
return string.Format("{0} <a href='{1}'>{2}</a>", description, replyToAddress, replyToText);
}
精彩评论