0

Iam geyying Error like The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

my code is

protected void SendEmail_Click(object sender, EventArgs e) {

  //  reading info from web.config file
    string HostAdd = ConfigurationManager.AppSettings["host"].ToString();
    string Sender = ConfigurationManager.AppSettings["MyEmail"].ToString();
    string MyPassword = ConfigurationManager.AppSettings["Password"].ToString();



    //creating MailBox Object
    MailMessage Email = new MailMessage();
    Email.From = new MailAddress(Sender);
    Email.Subject = "Interview";
    Email.Body = "EmailBodytxt.Text";
    Email.IsBodyHtml = true;


    //Gettting All Shortlisted Applicants Email ID
    string JobID = Request.QueryString["Qstring"];
    string Query = "select E_mail from Users inner join Apply on Apply.Applicant_CNIC =Users.User_ID where Users.Role='Applicant' and Apply.Status='Shortlisted' and Apply.Job_ID=" + JobID + "";
    DataTable EmailDT = DataTableClass.GetDataset(Query);

    foreach (DataRow E_Address in EmailDT.Rows)
    {
        string ID = E_Address["E_Mail"].ToString();
        //  Email.To.Add(new MailAddress(E_Address["E_Mail"].ToString()));
        Email.To.Add(new MailAddress(ID));
    }


    SmtpClient smtp = new SmtpClient();
    smtp.Host = HostAdd;

    //network and security Managment
    smtp.EnableSsl = true;
    NetworkCredential NetworkCred = new NetworkCredential();
    NetworkCred.UserName = sender.ToString();
    NetworkCred.Password = MyPassword;

    smtp.UseDefaultCredentials = false;
    smtp.Credentials = NetworkCred;
    smtp.Port = 587;
    smtp.Send(Email);//sending Email




    //client.Send(msg);
}
  • `NetworkCred.UserName = sender.ToString();` Are you sure, that in the sender object is the username? So you would have a dynamic username and a static password. Makes no sense to me. – Ben Aug 02 '17 at 05:38
  • possible duplicate [Send e-mail via SMTP using C#](https://stackoverflow.com/questions/9201239/send-e-mail-via-smtp-using-c-sharp) – BMaximus Aug 02 '17 at 05:41

0 Answers0