При отправке почты он показывает ошибку как system. indexoutofrangeexception: email
При отправке электронной почты я получаю ошибку как
System.IndexOutOfRangeException: Email
Пожалуйста, кто-нибудь может сказать мне, почему это происходит.
Что я уже пробовал:
<pre lang="C#">string uniqueCode = string.Empty; SqlCommand cmd = new SqlCommand(); SqlDataReader dr; try { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MatriModel"].ConnectionString); if (con.State == ConnectionState.Closed) { con.Open(); } // get the records matching the supplied username or email id. cmd = new SqlCommand("select FullName from tblProfile where Email COLLATE Latin1_general_CS_AS=@emailId", con); cmd.Parameters.AddWithValue("@emailId", Convert.ToString(txtEmail.Text.Trim())); dr = cmd.ExecuteReader(); cmd.Dispose(); if (dr.HasRows) { string username = string.Empty; dr.Read(); username = dr["FullName"].ToString(); //generate unique code uniqueCode = Convert.ToString(System.Guid.NewGuid()); //Updating an unique random code in then UniquCode field of the database table cmd = new SqlCommand("update tblProfile set UniqueCode=@uniqueCode where Email=@emailid", con); cmd.Parameters.AddWithValue("@uniqueCode", uniqueCode); cmd.Parameters.AddWithValue("@emailid", txtEmail.Text.Trim()); StreamReader reader = new StreamReader(Server.MapPath("~/ForgotPasswordTemp.html")); string readFile = reader.ReadToEnd(); string myString = ""; myString = readFile; myString = myString.Replace("$$User$$", username); myString = myString.Replace("$$EmailId$$", txtEmail.Text); myString = myString.Replace("$$Url$$", "http://localhost:18601/ResetPassword.aspx?emailId=" + txtEmail.Text + "&uCode=" + uniqueCode + ""); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage("abc@syssigma.com", dr["Email"].ToString(), "You requested for change in Password.", myString.ToString()); System.Net.NetworkCredential mailAuthenticaion = new System.Net.NetworkCredential("abc@syssigma.com", "MyPassword"); System.Net.Mail.SmtpClient mailclient = new System.Net.Mail.SmtpClient("relay-hosting.secureserver.net", 25); mailclient.EnableSsl = false; mailclient.UseDefaultCredentials = false; mailclient.Credentials = mailAuthenticaion; mail.IsBodyHtml = true; mailclient.Send(mail); dr.Close(); dr.Dispose(); cmd.ExecuteReader(); cmd.Dispose(); con.Close(); lblMessage.ForeColor = Color.Green; lblMessage.Font.Bold = true; lblMessage.Text = "Password has been sent to your email address."; txtEmail.Text = "";
Мой Html-файл, который я хочу отправить, это
<!DOCTYPE html> <html> <head> <title>Vivahik</title> <meta charset="utf-8" /> </head> <body class="aAU"> <table border="0" cellpadding="0" cellspacing="0" width="520"> <tbody> <tr> <td style="padding:5px;font-family:Arial,MS Sans serif,Arial,Verdana,Helvetica;font-size:9px;font-style:normal;text-transform:none;color:#a6a6a6"> You are receiving this mail as a registered member of Vivahik.com. Please add <a href="#" target="_blank">info@Vivahik.com</a> to your address book to ensure delivery into your inbox. </td> </tr> </tbody> </table> <table cellpadding="0" cellspacing="0" border="0" width="520" style="border:1px solid #6c6c6c"> <tbody> <tr style="background:#c22143"> <td valign="top" style="padding:15px 20px"> <img src="images/logo.png" width="110" height="40" style="background:#c22143" border="0" alt="" class="CToWUd"> </td> </tr> <tr> <td valign="middle" height="55" style="vertical-align:middle;padding-left:15px;font:normal 20px Georgia;color:#ffffff" bgcolor="#f89722"> Forgot password </td> </tr> <tr> <td valign="top" style="padding:15px 20px;font:normal 12px arial;color:#363636;line-height:18px"> <span style="display:block;padding-bottom:5px"><b>Dear $$User$$<!-- (Label) -->,</b></span> You have recently requested for help with your login password. Changing your password is quite simple.<br><br>Click on the Email ID to change your password.(It is only one time access)<br><br> </td> </tr> <tr> <td style="padding-left:20px"> <table width="200" cellpadding="0" cellspacing="0" style="font:normal 12px/15px verdana,tahoma;color:#9a440d" border="0"> <tbody> <tr> <td align="left"> Registered Email ID </td> </tr> <tr> <td align="left" height="5"></td> </tr> <tr> <td align="left"> <a style="text-decoration:none" href="$$Url$$" target="_blank"> $$EmailId$$ </a> </td> </tr> <tr height="15"></tr> </tbody> </table> </td> </tr> <tr> <td valign="top" style="padding:10px 20px 15px;font:normal 12px arial;color:#363636"> <b>Wishing you the best life partner,</b><br>Team - Vivahik </td> </tr> </tbody> </table> <table cellpadding="0" cellspacing="0" width="520" border="0"> <tbody> <tr> <td valign="top" style="padding-left:5px;padding-right:3px;padding-top:3px;padding-bottom:3px;font:normal 9px arial;text-align:justify;color:#a6a6a6" bgcolor="#ffffff"> You are a Vivahik.com member. This e-mail comes to you in accordance with Vivahik.com's Privacy Policy. <a href="#" style="text-decoration:underline;color:#a6a6a6" target="_blank"> Click here </a> to unsubscribe. Vivahik.com is not responsible for content other than its own and makes no warranties or guarantees about the products or services that are advertised. </td> </tr> </tbody> </table> </body> </html>