2016-04-27 103 views
1

我使用電子郵件發送鏈接以創建密碼,但是在發送電子郵件鏈接時,我附加了我的激活碼以顯示鏈接,但它不顯示當我點擊鏈接,雖然在調試中我得到了激活碼的鏈接。下面是我的代碼添加鏈接在主體部分點擊鏈接後,激活碼不會在URL中顯示

[email protected]"<br /><a href='http://localhost:49234/Index.aspx?ActivationCode='"+objUserDetailsBE.ActivationCode+"'>Create a login to account</a>"; 

我讓我只能做到http://localhost:49234/Index.aspx?ActivationCode=在瀏覽器中點擊後鏈接,請讓我知道我做錯了。 添加的代碼按在註釋:

string emailAddress = txtEmailAddress.Text; 
string subject = "Login Credentials For Nth Star"; 
string body = string.Format("Hello,");       
[email protected]"<br /><a href='http://localhost:49234/Index.aspx?ActivationCode='"+objUserDetailsBE.ActivationCode+"'>Create a login to account</a>"; 
Email.SendMail(objemail, emailAddress, subject, body, ""); 

以下是我的「的SendMail」方法

public static bool SendMail(EmailConfigurationBE objEmailConfig, string toEmailAddresses, string subject, string body, string mailAttachments) 
    { 
     char[] splitter = { ';' }; 
     MailMessage mailMessage = new MailMessage(); 
     mailMessage.From = new MailAddress(objEmailConfig.Email); 
     mailMessage.Subject = subject; 
     mailMessage.Body = body; 
     mailMessage.IsBodyHtml = true; 
     mailMessage.Priority = MailPriority.High; 
     string[] multi = toEmailAddresses.Split(';'); 
     string[] multipath = mailAttachments.Split(';'); 
     foreach (string MultiemailId in multi) 
     { 
      mailMessage.To.Add(new MailAddress(MultiemailId)); 
     } 
     if (mailMessage.To.Count > 0) 
     { 
      //Adding Multiple Attachments 
      if (mailAttachments != "") 
      { 
       foreach (string Multipath1 in multipath) 
       { 
        Attachment attachFile = new Attachment(Multipath1); 
        mailMessage.Attachments.Add(attachFile); 
       } 

      } 
      SmtpClient smtpClient = new SmtpClient(); 
      try 
      { 
       smtpClient.Host = objEmailConfig.SMTPServer; 
       smtpClient.EnableSsl = EnableSsl; 
       System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(); 
       NetworkCred.UserName = objEmailConfig.Email; 
       NetworkCred.Password =objEmailConfig.Password; 
       smtpClient.UseDefaultCredentials = true; 
       smtpClient.Credentials = NetworkCred; 
       smtpClient.Port =Convert.ToInt32(objEmailConfig.PortNumber); 
       smtpClient.Send(mailMessage); 
       return true; 
      } 
      catch 
      { 

       mailMessage = null; 
       smtpClient = null; 
       return false; 
      } 
     } 
     else 
     { 
      return false; 
     } 
    } 
+0

你可以發佈更大的代碼塊嗎?目前還不清楚你在哪裏產生這種情況,你以後如何使用這個「body」變量 – Andrei

+0

@Andrei現在檢查並讓我知道是否需要更多東西。 – Steve

回答

1

它看起來像一個簡單的報價問題。看

<a href='http://localhost:49234/Index.aspx?ActivationCode='"+objUserDetailsBE.ActivationCode+"'

在這裏你有一個單引號http之前,另外一個ActivationCode=後第三個結尾。看起來像一個是多餘的,這打破了你的標記。

正確的版本:

[email protected]"<br /><a href='http://localhost:49234/Index.aspx?ActivationCode="+objUserDetailsBE.ActivationCode+"'>Create a login to account</a>"; 

我做的唯一的變化是ActivationCode=後刪除單引號。

還要確保活動代碼不包含引號或<>等符號,這些符號也可能會破壞標記。

+0

謝謝隊友!有用 – Steve

相關問題