简体   繁体   中英

The server response was: 5.7.0 Authentication Required in C# web hosting website

Recently I am working on sending mail by c# coding and I tryed to send mail by c# coding on visual studio platform and it's work totally fine in my localhost of visual studio. but when I run that same code over other hosting website like myASP.NET or Somee.com that time that code getting error.

error like (if I used smtp.gmail.com then error like

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at)

and (if I used smtp.somee.com then error generate like

Failure sending mail.)

Sending mail Code in c# is,

String username = "";
      string password = "";
      OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["cstring"].ConnectionString);
      OleDbCommand cmd = new OleDbCommand("select umail, lpwd from uregister where umail=@email", con);
      cmd.Parameters.AddWithValue("email", txtEmail.Text);
      con.Open();
      using(OleDbDataReader sdr = cmd.ExecuteReader()) {

          if (sdr.Read()) {
              username = sdr["umail"].ToString();
              password = sdr["lpwd"].ToString();

          }

      }
      con.Close();
         if (!string.IsNullOrEmpty(password)) {

            MailMessage Msg = new MailMessage();
              // Sender e-mail address.
              Msg.From = new MailAddress(txtEmail.Text);
              // Recipient e-mail address.
              Msg.To.Add(txtEmail.Text);
              Msg.Subject = "Your Password Details";
              Msg.Body = ("Your Username is:" + username + "<br/><br/>" + "Your Password is:" + password);
              Msg.IsBodyHtml = true;
              // your remote SMTP server IP.
               SmtpClient Smtp = new SmtpClient();
              Smtp.Host = "";
             Smtp.Port = 587;
            NetworkCredential ntwd = new NetworkCredential();
                    ntwd.UserName = "xyz@gmail.com"; //Your Email ID
          ntwd.Password = "xyz123."; // Your Password
            Smtp.UseDefaultCredentials = false;
          Smtp.Credentials = ntwd;

          Smtp.EnableSsl = true;
          Smtp.Send(Msg);

              lbltxt.Text = "Your Password Details Sent to your mail.";
              // Clear the textbox valuess
              txtEmail.Text = "";
          }
          else
          {
              lbltxt.Text = "The Email you entered not exists.";
          }

this code is not work on hosting site somee.com/myASP.NET. so please let me know what is problem in this code..

In your case, you should provide strong password as per domain policy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM