Click here to Skip to main content
15,039,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi developers!!

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..

What I have tried:

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.gmail.com";
               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.";
            }
Posted
Updated 30-May-20 20:05pm

1 solution

See the answers here: failure sending mail[^]

As you seem to use an old version of the .NET framework this could also cause problems with SSL, the simplest solution is to upgrade to the newest version.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900