Reputation: 13
I am doing Confirmation mail sent to the register following with this URL
but i am getting errors.Can anyone help me.
message.Subject = "Please Verify your Account";
MailBody.Append("<html><table cellpadding='0' cellspacing='0' width='100%' align='center'>" + "<tr><td><p>Dear " + user.UserName+ "</p><br>");
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'> <a href=verifyUrl + "\" target="http://localhost:51819">" + verifyUrl + "+"</a></span> to complete your registration.<br>);
Upvotes: 1
Views: 88
Reputation: 75083
Your New line in constant
is due to the fact you're breaking the line without telling the compiler that you want a second line.
There is 3 ways you can fix this:
@
sign to do what you wantAs an example:
StringBuilder sb = new StringBuilder();
sb.Append("<html><table cellpadding='0' cellspacing='0' width='100%' align='center'>");
sb.Append("<tr><td><p>Dear " + user.UserName+ "</p><br>");
sb.Append("To verify your account, please click the following link:<span style='font-weight:bold;'>");
sb.Append("<a href='" + verifyUrl + "' target='http://localhost:51819'>" + verifyUrl + "</a></span> to complete your registration.<br>");
MailBody.Append(sb.ToString());
You also need to avoid using a mix of single and double quotes inside a string, the idea is to only use single quotes inside and use double quotes to delimit the string.
You can also use the @
in front of a string and you can then break the line like this:
MailBody.Append(
String.Format(
@"<html>
<table cellpadding='0' cellspacing='0' width='100%' align='center'>
<tr>
<td>
<p>Dear {0}</p>
To verify your account, please click the following link:
<span style='font-weight:bold;'>
<a href='{1}'>{1}</a>
</span> to complete your registration.
</td>
</tr>
</table>
</html>", user.UserName, verifyUrl));
I also used StringBuilder
to avoid having variables inside the template, as it makes it way more simple to see and edit.
And last, but not least, you should know a little bit more about HTML ... there is no such thing as target="http://localhost:51819"
...
Upvotes: 2
Reputation: 29694
Your second MailBody.Append
is all messed up
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'> <a href="+verifyUrl + "\" target=\"http://localhost:51819\">" + verifyUrl + "</a></span> to complete your registration.<br>");
Upvotes: 0
Reputation: 20674
You are missing quotes in your second append. The script highlighter even shows the error.
If you want double quotes within a string it needs to be escaped, e.g. \"
So your second appending should be something like this
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'><a href=\""
+ verifyUrl + "\" target=\"http://localhost:51819\">"
+ verifyUrl + "</a></span> to complete your registration.<br>");
Upvotes: 2