6

I'm building a string that will be sent over email. In the string I'd like to include a link, like so:

String mailstring = "Blah blah blah blah. Click here for more information."

and I'd like the "here" to be a link in the email, such as putting it http://madeuplink.com. I know I can put the address instead of the 'here' but I'd like to have the link be the word.

3 Answers 3

8

You can add HTML markup. Assuming the client has HTML emails enabled, it should become a link. If you're using MailDefinition to create the email, then ensure that the IsBodyHtml property is set to true.

String mailstring = "Blah blah blah blah. Click <a href=\"http://www.example.com\">here</a> for more information."
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, I did not know that html markup would work for this, thanks.
Hey is there some kind of Namespace I need include or a reference? This isn't working for me... :( m_sMessage = "To learn more about FabPro1, Visit <a href=\"http://www.fabpro1.com\">our website</a>";
@UchihaItachi You'll need to add System.Web
3
 string input = String.Format("Blah blah blah blah. Click {0} for more information.", 
                    "<a href=\"http://www.example.com\">here</a>");

OR

 string input = "Blah blah blah blah. Click <a href=\"http://www.example.com\">here</a> for more information.", 

Comments

1

Just one thing to add to @keyboardP's comment even though it is a bit out of context, if you are using MailMessage object to be sent as a message using SmtpClient, you need to set the MailMessage.IsBodyHtml = true.

public void SendEmail(string to, string subject, string body) { MailMessage mail = new MailMessage("[email protected]", to); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; ... }

The HTML markup will take the desired form in the email only when this property is set, otherwise it will show the markup as text and not a hyperlink.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.