1

I am doing Confirmation mail sent to the register following with this URL

http://blogs.microsoft.co.il/blogs/shair/archive/2011/12/06/email-confirmation-asp-net-mvc-web-application.aspx#comments

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>);
4

3 に答える 3

2

これは、コンパイラNew line in constantに2行目が必要であることを通知せずに行を分割しているためです。

これを修正する方法は3つあります。

  • 行を壊さないでください
  • すべての特殊文字をエスケープする
  • サインを使っ@てやりたいことをする

例として:

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());

また、文字列内で一重引用符と二重引用符を混在させないようにする必要があります。アイデアは、文字列内で一重引用符のみを使用し、二重引用符を使用して文字列を区切ることです。

@文字列の前でinを使用して、次のように行を分割することもできます。

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));

またStringBuilder、テンプレート内に変数を含めることを避けていました。これにより、表示と編集がより簡単になります。

そして最後に、重要なことですが、HTMLについてもう少し知っておく必要があります...そのようなことはありませんtarget="http://localhost:51819"...

于 2012-12-20T09:53:41.367 に答える
2

2 番目の追加で引用符がありません。スクリプトの蛍光ペンにもエラーが表示されます。

文字列内に二重引用符が必要な場合は、\" のようにエスケープする必要があります。

したがって、2番目の追加は次のようになります

  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>");
于 2012-12-20T09:43:01.577 に答える
0

あなたの2番目MailBody.Appendはすべて台無しです

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>");
于 2012-12-20T09:45:48.743 に答える