jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.
http://www.mimekit.net
MIT License
6.23k stars 824 forks source link

Authentication Failed Exception #216

Closed l-o-l closed 9 years ago

l-o-l commented 9 years ago

Using the example SMTP send email code and this "dummy" smtp server:

https://nilhcem.github.io/FakeSMTP/

I get an AuthenticationException (Authentication Failed).

Protocol Log:

Connected to smtp://127.0.0.1:25/?starttls=when-available S: 220 XXXXXX ESMTP SubEthaSMTP null C: EHLO [127.0.0.1] S: 250-XXXXXX S: 250-8BITMIME S: 250-AUTH LOGIN S: 250 Ok C: AUTH LOGIN QmVuLkdyYWhhbUBvdXRsb29rLmNvbQ== S: 334 VXNlcm5hbWU6 C: S: 334 UGFzc3dvcmQ6 C: AUTH LOGIN QmVuLkdyYWhhbUBvdXRsb29rLmNvbQ== S: 235 Authentication successful.

Mailkit Version: 1.2.7.0

Code works fine against GMAIL and legacy code (which I am looking to replace) works fine against this server.

jstedfast commented 9 years ago

Most real-world servers support an initial-response argument when using the SASL LOGIN mechanism, but it appears that FakeSMTP does not which is why you got an exception.

The LOGIN mechanism never made it into an accepted standard (it was abandoned as a draft and expired in 2004) and so FakeSMTP really should update their code to support the PLAIN mechanism which is the replacement for LOGIN.

l-o-l commented 9 years ago

Thanks for answering this so quickly. The code I am looking to replace is in a product that has a large install base using all and sundry commercial email servers. Is this FakeSTMP thing simply bugged, or is it likely to pop up in another server somewhere?

jstedfast commented 9 years ago

It's not likely to pop up in a real-world server for 2 reasons:

  1. It's incredibly rare (possibly even non-existent) for any SMTP server to support LOGIN but not also support PLAIN and MailKit prefers PLAIN over LOGIN because LOGIN is obsolete/deprecated in favor of PLAIN.
  2. Most SMTP servers that I've encountered, at least, that support LOGIN allow the client to send the base64-encoded username in the AUTH command.

I plan on making a new release of MimeKit and MailKit this weekend anyway, so you won't have to wait very long for the next release.

Hope that helps.