SmtpClient issue. The SMTP server requires a secure connection or the client was not authenticated. Exchange response: Client was not authenticated

Hi all,


I have a problem using ‘Aspose.Email.Mail.SmtpClient’. In my scenario it is used to send messages to Exchange.

I use following code:
Aspose.Email.Mail.SmtpClient aCl = new Aspose.Email.Mail.SmtpClient(“ip”, port);
aCl.Username = “testUser”;
aCl.Password = “password”;
aCl.Send(new Aspose.Email.Mail.MailMessage(“testUser@test.lab”, “testUser@test.lab”, “sunject”, “body”));

But i get an SMTP error: The SMTP server requires a secure connection or the client was not authenticated. Exchange response: Client was not authenticated

I tried different aCl.AuthenticationMethod but got the same result.

But everything works fine if i use System.Net.Mail.SmtpClient:

System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(“host”);
client.Port = port;
client.Credentials = new NetworkCredential(“testUser”, “password”);
client.Send(new System.Net.Mail.MailMessage("testUser@test.lab ", "testUser@test.lab ", “subject”, “body”));


I use: Exchange 2010

Cah anybody give an advice?

Hi Alex,

Thank you for using Aspose.Email.

It seems that you are trying to connect to an SSL enabled server, but not specifying the proper properties for SMTPClient object. For SSL enabled servers, you need to explicitly set the settings for SSL mode and specify the SSL port, as you can see here in this article .

I have made a little changes to your code and the code below works fine from my Gmail account to Exchange Server 2010. Please have a look at the following code for your reference.

Aspose.Email.Mail.SmtpClient client = new Aspose.Email.Mail.SmtpClient("smtp.gmail.com", 587);

// set the security mode to explicit

client.SecurityMode = SmtpSslSecurityMode.Explicit;

// enable SSL

client.EnableSsl = true;

//set the username and password

client.Username = "newcustomeronnet@gmail.com";

client.Password = "password";

//now send the MailMessage

client.Send(new Aspose.Email.Mail.MailMessage("sender@gmail.com", "receiver@xyz.com", "Subject2", "This is body"));

Please give a try to this code and let us know your feedback.

You can also find additional information about Sending Email messages with SMTP by visiting our product documentation section HERE .

I tried this code and got an error:

  • Type: AuthenticationException
  • Message: The remote certificate is invalid according to the validation procedure.
Also tried this:
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

I forgot to give the information adbout Exchange Receive Connector which is used.
Its settings allow “Basic Authentication” only after starting TLS.

Here is a link to screenshot of “Authentication” tab of Connector properties window LINK



Fixed!)))


Found answer here.
I do use self-signed certificate. Spicified host name as in server’s certificate (before i tried to use IP adrdess)

Hi,


Thank you for sharing your findings with us. It will definitely be of help to other forum members as well.

Its good to know that your problem is solved now. If you have any other query, please feel free to contact us. We will try our best to assist you as soon as possible.