Search code examples
c#authenticationcredentialshostsmtpclient

Visual C# SmtpClient could never get authenticated


I have tried gmail, yahoo, and hotmail hosts, and I'm 100% sure that my username and password is correct. But no matter how I tried, I could NEVER get my credential authenticated.

It keep showing me this error:

enter image description here

The Chinese part roughly means "SMTP Server Required a Secure Connection, or the Client Credential is not Authenticated. Server Replies: 5.7.1"

Where did I go wrong?


Solution

  • Try to declare your client.Credentials after client.UseDefaultCredentials

    client.UseDefaultCredentials = false;
    client.Credentials = new blabla;
    

    Just rearrange the codes something like you are composing email.

    From
    To
    Subject
    Email Body
    

    then your Port, UseDefaultCredentials, Credentials and last one is Send

    You have to see this similar to your problem.