1

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);
    }
18
  • @Manjusha please edit your question and put the formatted code there, rather than a comment. Commented Oct 22, 2012 at 12:42
  • Make sure you change that password so people don't use your sever as a relay. You wouldn't want your server to become blacklisted. Commented Oct 22, 2012 at 12:46
  • where is SmtpClient object initialization? Commented Oct 22, 2012 at 12:46
  • client.Host = "pod51018.outlook.com"; client.Port = 587; Commented Oct 22, 2012 at 12:50
  • any errors are there in the above code plz let me know Commented Oct 22, 2012 at 13:06

2 Answers 2

0

Just like the message states, you're not authenticated.

In your code:

string EmailFrom = "";
string EmailFromPassword = "";

        System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(EmailFrom, EmailFromPassword);

If this is your exact code - you're passing an empty username and password..

Sign up to request clarification or add additional context in comments.

8 Comments

No am sending my credentials emailid and password
@Manjusha - So in your code EmailFrom and EmailFromPassword have the correct username/password inside them?
@Blachshma - Previously it was worked now its showing that exception
Did you try switching to port 995 instead of 587?
@Blachshma- No i will try once
|
0

You will need to check the following details are correct (as in the details shown on your Office 365 panel)

  1. Host Name
  2. E-Mail Address
  3. Password

The code appears good (assuming your actually passing an address/password since it's a blank string in your code) so it's likely an issue in your settings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.