Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how render string to html link

Tags:

html

c#

hyperlink

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.

like image 774
Jeyhun Rahimov Avatar asked Aug 15 '12 19:08

Jeyhun Rahimov


3 Answers

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() ));
like image 102
codingbiz Avatar answered Oct 05 '22 23:10

codingbiz


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.

like image 20
Nick Avatar answered Oct 06 '22 00:10

Nick


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;
like image 23
Adriano Carneiro Avatar answered Oct 06 '22 01:10

Adriano Carneiro