Larry Wim
Larry Wim

Reputation: 21

ASP.NET format of href in Email body shows entire link instead of text

I'm implementing two-factor authorization using asp.net identity 2.1. Sending the email with the link for confirmation works correctly, but I ran into a problem trying to format the body of the email. For those familiar with Identity 2.1, here's the code I use to send the email:

await UserManager.SendEmailAsync(user.Id, "Reset Password", "Paragraph 1\n\nParagraph 2\n\nClick the reference below\n\n<a href=\"" + callbackUrl + "\">Link</a>");

I was expecting just the word "Link" to appear as hypertext, but instead the whole link appears not just the word 'Link'. In the email, the body appears as expected until you get to the link and it appears as:

Link". The link url is all underlined as hypertext, but the leading "Link" appear as plain text. If you click the link, it works exactly as expected. I've tried using string.format and I've looked at other examples that illustrate with sample screen captures the look I want, just the word "Link" as hypertext, and I've actually copied their code and it still doesn't work.

What am I overlooking or doing wrong here? Any suggestions would be appreciated.

Cheers, Larry

Upvotes: 1

Views: 857

Answers (1)

Larry Wim
Larry Wim

Reputation: 21

The solution was very simple. You have to make sure the body of the message you send is in HTML format. So include the following in your Email Service:

message.IsBodyHTML = true;

where message is IdentityMessage (in the case of ASP.Net Identity 2.1)

Very simple solution and couldn't believe I didn't think of it or find it already answered, like here!

Cheers, Larry

Upvotes: 1

Related Questions