问题
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.
回答1:
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() ));
回答2:
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.
回答3:
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;
回答4:
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 :)
回答5:
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;
来源:https://stackoverflow.com/questions/11975483/how-render-string-to-html-link