Click here to Skip to main content
15,891,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i hv a error
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. kr4sm12198444pbc.76
durin sending email


.cs

C#
NetworkCredential nt = new NetworkCredential("*************@gmail.com", "12345678");
                   string usermail = ds.Tables[0].Rows[0][0].ToString();
                   string passwd = ds.Tables[0].Rows[0][1].ToString();
                   MailMessage mail = new MailMessage();
                   SmtpClient smtp = new SmtpClient();
                   smtp.Credentials = nt;
                   mail.From = new MailAddress(Text2.Value);
                   mail.To.Add(new MailAddress(usermail));
                   mail.IsBodyHtml = true;
                   mail.Subject = "Password";
                   mail.Body = "Your password is : " + passwd + "";
                   smtp.Host = "smtp.gmail.com";
                   smtp.Port = 587;
                   smtp.Send(mail);//here is error
                   lbl.Visible = true;
                   lbl.Text = "password sent successfully";
                   mail.To.Clear();
                   mail.Dispose();


what should i do....
Posted
Updated 17-Oct-12 0:04am
v2

private void MailSendThruGmail()
    {
        MailAddress fromAddress = new MailAddress("sender@gmail.com", "From Name");
        MailAddress toAddress = new MailAddress("recipient@gmail.com", "To Name");
        const string subject = "test";
        const string body = @"Using this feature, you can send an e-mail message from an application very easily.";

        System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(fromAddress.Address, toAddress.Address, subject, body);
        msg.IsBodyHtml = true;

        var client = new SmtpClient("smtp.gmail.com", 587)
        {
            Credentials = new NetworkCredential("username", "password"),
            EnableSsl = true
        };

        try
        {
            client.Send(msg);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }
 
Share this answer
 
Please do not use Gmail for testing. Use your own local email server, like HmailServer, which is free.
 
Share this answer
 
C#
MailMessage message = new MailMessage();



            message.From = new MailAddress("Ngqandu.Anele@gmail.com");

            message.To.Add(new MailAddress("Anele.Ngqandu@live.nmmu.ac.za"));

            message.Subject = subject.Text;

            message.Body = body.Text;



            SmtpClient client = new SmtpClient();

            client.Credentials = new System.Net.NetworkCredential("Ngqandu.Anele@gmail.com", "password");



            client.Port = 587;

            client.Host = "smtp.gmail.com";

            client.EnableSsl = true;

            try

            {

                client.Send(message);

            }

            catch (Exception ex)

            {

                System.Windows.Forms.MessageBox.Show(ex.Message);

            }
 
Share this answer
 
easy code for sending main

C#
protected void Button1_Click(object sender, EventArgs e)
  {

      str = "Department :" + DropDownList1.SelectedItem;
      str = str + "\nName : " + TextBox1.Text;
      str = str + "\nEmail : " + TextBox2.Text;
      str = str + "\nContact : " + TextBox3.Text;


      try
      {

          Email("dksingh6788@gmail.com", "dksingh6788@gmail.com", str);
          Label6.Visible = true;
      }
      catch { }

  }

  public bool Email(string strFrom, string strTo, string strMessage)
  {
      try
      {
          if (strFrom.Trim() != "" && strTo.Trim() != "" && strFrom.Trim() != null && strTo.Trim() != null)
          {
              System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage();
              objMailMessage.Body = strMessage;
              objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
              objMailMessage.IsBodyHtml = false;
              objMailMessage.From = new MailAddress(strFrom, "New Enquiry", System.Text.Encoding.UTF8);
              objMailMessage.To.Add(new MailAddress(strTo));
              //objMailMessage.CC.Add(new MailAddress(strTo));
              objMailMessage.Subject = "Registration Request";
              objMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
              objMailMessage.Priority = MailPriority.High;
              //if (FileUpload1.HasFile)
              //{
              //    objMailMessage.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
              //}

              try
              {

                  System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient();
                  objSMTPClient.Credentials = new System.Net.NetworkCredential(strFrom, "lalakidukan");
                  //objSMTPClient.Credentials = objSMTPClient.Credentials.GetCredential(objSMTPClient.Host, objSMTPClient.Port, "Digest");
                  objSMTPClient.Port = 587;
                  objSMTPClient.Host = "smtp.gmail.com";
                  objSMTPClient.EnableSsl = true;
                  //objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                  objSMTPClient.Send(objMailMessage);

              }
              catch (Exception ex)
              {
                  return false;
              }
              Label6.Visible = false;
              TextBox1.Text = "";
              TextBox2.Text = "";
              TextBox3.Text = "";

          }
      }
      catch (Exception ex)
      {
          return false;
      }
      return true;
  }
 
Share this answer
 
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