Reputation: 2305
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.
Upvotes: 6
Views: 28502
Reputation: 2676
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.
Upvotes: 1
Reputation: 26396
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.",
Upvotes: 3
Reputation: 69372
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."
Upvotes: 8