cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
692 stars 163 forks source link

Authentication Issue #120

Closed srosam closed 3 years ago

srosam commented 4 years ago

Hi. I'm attempting to test some code that used authentication to send mail.

It connects and sends the mail to a real external smtp server but I cannot figure out how to get this working in my test code.

I have built up this options object:

var options = new SmtpServerOptionsBuilder()
  .ServerName(server)
  //.Port(port, isSecure: false)
  .MessageStore(_localMessageStore)
  .UserAuthenticator(new SampleUserAuthenticator())
  .Endpoint(builder 
    => builder
     .Port(port, false).AllowUnsecureAuthentication(false))
  .Build();

The 'SampleUserAuthenticator' just returns true but is never called.

However my client gets back an error when attempting to authenticate: "The SMTP server does not support authentication."

srosam commented 4 years ago

This, .Endpoint(builder => builder .Port(port, false) .AllowUnsecureAuthentication() .AuthenticationRequired() )

Resolved it

cosullivan commented 4 years ago

Hi,

Glad that you have resolved it.

The reason it didn't work in your first example was because of setting

AllowUnsecureAuthentication(false)

If you have this set to false (which is the default) and don't supply a Certificate then it wont advertise the AUTH PLAIN LOGIN command to the client and therefore the client correctly determines that the server doesn't support authentication.

Thanks, Cain.