Quote:An exception of type 'System.Net.Mail.SmtpFailedRecipientException' occurred in App_Web_2woqyecp.dll but was not handled in user code
Quote:Additional information: Mailbox unavailable. The server response was: 5.7.1 Unable to relay
public void forgot() { string username = ""; SqlConnection con = new SqlConnection(strConnString); SqlCommand cmd = new SqlCommand(spgetuser, con); cmd.Parameters.AddWithValue("@email", txtEmailP.Text); con.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) { username= dr["username"].ToString(); } } con.Close(); if (!string.IsNullOrEmpty(username)) { try { string emailFrom = "me@example.com"; string body = "<div style='border: medium solid grey; width: 500px; height: 266px;font-family: arial,sans-serif; font-size: 17px;'>"; body += "<h3 margin-top:0px;'>Username Recovery</h3>"; body += "<br />"; body += ("Your Username is: " + username); body += "<br />"; body += "<br />"; body += "Kinds Regards"; body += "<br />"; body += "</div>"; System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); //message.To.Add(emailTo); //message.Subject = subject; message.From = new System.Net.Mail.MailAddress(emailFrom); message.IsBodyHtml = true; message.Body = body; message.Priority = System.Net.Mail.MailPriority.High; message.Subject = "username Recovery"; message.From = new System.Net.Mail.MailAddress(emailFrom); SmtpClient SmtpMail = new SmtpClient(); SmtpMail.EnableSsl = true; SmtpMail.Port = 25; SmtpMail.Host = "myhost"; System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; }; // compare session username to username in database SqlCommand command = new SqlCommand(spcheck,con) command.Parameters.AddWithValue("@email", txtEmailP.Text); using (SqlConnection connection = new SqlConnection(strConnString)) { connection.Open(); command.Connection = connection; SqlDataReader reader = command.ExecuteReader(); // Call Read before accessing data. while (reader.Read()) { var to = new MailAddress(reader["Email"].ToString()); message.To.Add(to); } // Passing values to smtp object SmtpMail.Send(message); ScriptManager.RegisterStartupScript(this, typeof(string), "Msg","alert('request has been sent');", true); Response.Redirect("~/lgn.aspx"); // Call Close when done reading. reader.Close(); } } catch (Exception ex) { throw ex; } } } protected void Button1_Click(object sender, EventArgs e) { this.forgot(); }
//message.To.Add(emailTo); //message.Subject = subject;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)