DarkW1nter
DarkW1nter

Reputation: 2861

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 " + txtdescription.Text +
             "<br />Reply to (click here):" + txtemail.Text);

Upvotes: 0

Views: 4362

Answers (4)

Greg
Greg

Reputation: 23493

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>");

Upvotes: 2

BrandonZeider
BrandonZeider

Reputation: 8152

Try this

    private string BuildEmailText(string description, string replyToAddress, string replyToText)
    {
        return string.Format("{0} <a href='{1}'>{2}</a>", description, replyToAddress, replyToText);
    }

Upvotes: 1

Devin Burke
Devin Burke

Reputation: 13820

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>");

Upvotes: 1

SLaks
SLaks

Reputation: 888087

You can write <a href='mailto:[email protected]'>Link Text</a>.

Upvotes: 1

Related Questions