Jeyhun Rahimov
Jeyhun Rahimov

Reputation: 3787

how render string to html link

I send some message to email as below:

string link = "http://localhost:1900/ResetPassword/?username=" + user.UserName + "&reset=" + HashResetParams( user.UserName, user.ProviderUserKey.ToString() );
email.Body = link;

This string was sent to email, but shown as string, not as link, I want send it as link to click.

Upvotes: 8

Views: 46792

Answers (5)

Phillip Schmidt
Phillip Schmidt

Reputation: 8818

string link = "<a href=http://localhost:1900/ResetPassword/?username=" + user.UserName + "&reset=" + HashResetParams( user.UserName, user.ProviderUserKey.ToString() + "> Link Text Here </a>");

It doesn't know that it's a link :)

Upvotes: 2

codingbiz
codingbiz

Reputation: 26396

Try this

string link = String.Format("<a href=\"http://localhost:1900/ResetPassword/?username={0}&reset={1}\">Click here</a>", user.UserName, HashResetParams( user.UserName, user.ProviderUserKey.ToString() ));

Upvotes: 10

Andy Clark
Andy Clark

Reputation: 3523

Changes the email body from Plain text to Html and generate the link using an <a> element

string link = @"<a href="www.mylink.com">link</a>"

email.IsBodyHtml = true;

Upvotes: 2

Adriano Carneiro
Adriano Carneiro

Reputation: 58645

Make it a link with the a HTML tag. And don't forget to set the MailMessage as HTML body:

string link = "http://localhost:1900/ResetPassword/?username=" + user.UserName + "&reset=" + HashResetParams( user.UserName, user.ProviderUserKey.ToString() );
email.Body = "<a href='" + link + "'>" + link + "</a>";
email.IsBodyHtml = true;

Upvotes: 3

Nick
Nick

Reputation: 9154

Wrap link in an anchor tag:

string link = '<a href="http://......">Click here to reset your password</a>';

and

email.IsBodyHtml = true;

Or combine them together using string concatenation and feed into email.Body. An email body is HTML, so it wont be a link unless you tell it to be one. Also, don't forget to tell it that the body is HTML, like I always do.

Upvotes: 5

Related Questions