1

I'm attempting to send an email using ASP.NET C#. The emails sends just fine. The problem is I am trying to embed a link within the email, but link on the client end is not recognised (as in it cant be recognised as a link by the browser)

I have tried putting the C# into one variable, I have tried to split the code into various variables but I am not too sure what I am doing wrong here. It could be how Im placing the ' or " to embed. not too sure.


string body = "Hello " + firstNameUser + ",";

body += "<br /><br />Please click the following link to activate your account";
body += "<br /><a href = '" + HttpContext.Current.Request.Url.Authority + "/Auth/Activation/Activation.aspx?ActivationCode=" + TwoFACode + "'>Click here to activate your account.</a>";

body += "<br /><br />Thanks";
body += "<br /><br />Support Team";

mail.Body = body;
mail.IsBodyHtml = true;
client.Send(mail);

'Please click the following link to activate your account' Cant be recognised meaning its not a clickable HTML Link. On the email all you can see is just text instead of a hyperlink.

2
  • "cant be recognised" means what exactly? You mean you click the link and it won't open the browser? Or you mean the browser opens but the URL doesn't navigate to to where you intended? It's a bit unclear. Also, have you viewed the source code of the email to check the HTML appears as you intended? Commented Sep 15, 2019 at 21:30
  • @ADyson Cant be recognised meaning its not a clickable HTML Link. On the email all you can see is just text instead of a hyperlink Commented Sep 15, 2019 at 21:55

1 Answer 1

1

It looks to me that you are missing something in the link:

body += "<br /><a href = 'https://" + HttpContext.Current.Request.Url.Authority + 
"/Auth/Activation/Activation.aspx?ActivationCode=" + 
TwoFACode + "'>Click here to activate your account.</a>";

Adding the needed https:// or http:// should fix it.

Uri.Authority Property

The Authority property is typically a server DNS host name or IP address. 
This property might include the service port number if it differs from the 
default port for the URI. If the Authority component contains reserved 
characters, these are escaped in the string value returned by this property.

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Have a look in my answer. Just copy the code and try it. The URL needs to start with http:// or https:// you don't have this in your code.
Great that it helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.