c# - Error sending email -


When the user forgot the password, I was the solution to recover the user's password. I did the code well, but the error appears with an SMTP exception (sending error). How can I fix this problem?

  Secure Wide Button 1_Click (Object Sender, EventAgps E) {Usage (SQL Connection Connection = Connection. Gate Connection ()) {string sql = "Select password from registration where username = @ Username and email = @ email "; SqlCommand Com = New SQL Commands (SKL, Kon); Com.CommandType = CommandType.Text; Com.Parameters.Add ("@username", SqlDbType.NVarChar, 50) .Value = TxtUserName.Text; Com.Parameters.Add ("@ Email", SqlDbType.NVarChar, 50). Valu = TxtEmail.Text; SqlDataReader dr = com.ExecuteReader (commandback.exerelease | Commandback.close connection); While (Dr. Reid ()) {SendMail ("karim-gamal@elarabygroup.com", "xxxx", TxtEmail.Text, "Hi", "Hi" + Dr. ["Password"]. ToString ()); } Response.Redirect (""); }} Public Static Bund Sendmail (string aliarbayaccount, string password, string to, string subject, string message) {try {NetworkCredential loginInfo = new network credentials (AllBaby account, password); MailMessage msg = New MailMessage (); Msg.From = New MailAdd (AllBarAccounts); Msg.To.Add (new mail address (from)); Msg.subject = Subject; Msg.Body = Message; Msg.IsBodyHtml = True; SmtpClient Client = New SmtpClient ("smtp.elarabygroup.com", 8080); Client.EnableSsl = true; Client.UseDefaultCredentials = false; Client Credentials = LoginInfo; Client.Send (MSG); Back true; } Hold (exception) {return false; }}  

The following states (emphasis is my):

The connection established by the current installation of SMTP Client class in the SMTP server can be used again if an application wants to send multiple messages to the same SMTP server. This is particularly useful when authentication or encryption is used to establish connection to SMTP server.

Since you use an SmtpClient example to send your mail to encryption ( client.EnableSsl = ) Should try.

In addition, by creating a new example of SmtpClient > on every call of SendMail , you are creating a new connection to the SMTP server; Depending on the number of records you have, and thus the number of emails sent by you, it is possible that the SMTP server refuses to accept any connection because of the high volume, because it can think that you Either DDOS attack or you are trying to do other malicious things.

As already mentioned above, try using a single smtpClient example.

Another possible issue may be that the SmtpClient is not leaving the connection correctly by not issuing a QUIT command, and Microsoft .NET Fixed in Framework 4.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -