Iam geyying错误就像 SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。
了解更多信息我的代码是
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);
}