Exception:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
I am not using Defaultcredentials, so I set client.UseDefaultCredentials = false;
Also, I provided valid email id and password, host name and port number; however, I am
still getting the same Exception. How can I resolve this issue? Thanks in advance for any help.
public void SendCustomerForgotPassword(string mailTo, string forgotUserId, string forgotPassword)
{
string mailSubject = "", mailBody = "";
mailSubject = "";
StringBuilder sbMailBody = new StringBuilder();
sbMailBody.AppendLine("Welcome to *****,");
sbMailBody.AppendLine("\r");
mailBody = sbMailBody.ToString();
SetSmtpClient(mailTo, mailSubject, mailBody);
}
private void SetSmtpClient(string recipients, string subject, string body)
{
string EmailFrom = "here set an email id";
string EmailFromPassword = "set password";
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(EmailFrom, EmailFromPassword);
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Host = "pod51018.outlook.com";
client.Port = 587;
client.UseDefaultCredentials = false;
client.Credentials = credentials;
client.Send(EmailFrom, recipients, subject, body);
}