Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthenticationException being thrown for non-authentication issues? #717

Closed
oatsoda opened this issue Jun 5, 2018 · 11 comments
Closed

AuthenticationException being thrown for non-authentication issues? #717

oatsoda opened this issue Jun 5, 2018 · 11 comments
Labels
enhancement New feature or request

Comments

@oatsoda
Copy link

oatsoda commented Jun 5, 2018

I am using the AuthenticationException to track when I think that the credentials are wrong, assuming that it would only throw when the SMTP Response Code are SmtpStatusCode.AuthenticationInvalidCredentials etc. but it seems that in actual fact this exception type can be thrown for any failure - is this correct?

Looking at the code all errors are thrown as an AuthenticationException:

var message = string.Format ("{0}: {1}", response.StatusCode, response.Response);
if (saslException != null)
authException = new AuthenticationException (message, saslException);
else
authException = new AuthenticationException (message);

The description suggests otherwise:

/// <exception cref="MailKit.Security.AuthenticationException">
/// Authentication using the supplied credentials has failed.
/// </exception>

I believe that I am getting AuthenticationExceptions with messages such as:

ServiceNotAvailable: 4.3.2 Service not active [AM6PR03CA0003.eurprd03.prod.outlook.com].

Which is problematic as the AuthenticationException does not have an StatusCode which I could inspect for more details.

How should I be detecting true failures of credentials?

@jstedfast
Copy link
Owner

You could try digging into the InnerException property. That should have the info you are looking for.

AuthenticationException -> SaslException -> SmtpCommandException

@oatsoda
Copy link
Author

oatsoda commented Jun 6, 2018

Thanks @jstedfast. Will take a look.

@oatsoda oatsoda closed this as completed Jun 6, 2018
@jstedfast
Copy link
Owner

If the InnerException suggestion doesn’t work, let me know and I’ll try to look into making changes to the code so you can get that info.

@jstedfast jstedfast added the enhancement New feature or request label Jun 7, 2018
@jstedfast
Copy link
Owner

It looks like my suggestion won't work now that I am looking at the code.

I'll commit a fix shortly.

@jstedfast
Copy link
Owner

FWIW, the nesting goes like this: AuthenticationException -> SmtpCommandException [ -> SaslException ]

@oatsoda
Copy link
Author

oatsoda commented Jun 7, 2018

@jstedfast Thanks for following up on this. I had just begun to look at how to get this working. I guess I will need to take the next version with the fix in!

So ultimately I can check for password/account specific failures by:

  • Checking for AuthenticationException
  • Checking it has an InnerException of type SmtpCommandException
  • Checking the StatusCode on the InnerException

Do you have an ETA on the next release of MailKit?

@jstedfast
Copy link
Owner

Probably not for a few weeks unless a major bug comes to my attention. I try to release every 4-6 weeks or so and I just made a release last week?

@oatsoda
Copy link
Author

oatsoda commented Jun 7, 2018

@jstedfast Any chance of a it being quicker? I'm fighting quite a major live issue with this :(

@oatsoda oatsoda reopened this Jun 8, 2018
@oatsoda oatsoda closed this as completed Jun 8, 2018
@jstedfast
Copy link
Owner

If I have time this weekend, I'll look into it. In the meantime, donations are welcome :)

@RickVM
Copy link
Contributor

RickVM commented Oct 7, 2019

Running into the same problem. I would like some way to figure out what went wrong if authentication fails.

InnerException is Null, Message is: "Login failed"

@jstedfast could you reopen this issue and look into it please?

@jstedfast
Copy link
Owner

The text "Login failed" likely came from the IMAP, POP3 or SMTP server.

You can get a protocol log like this:

using (var client = new SmtpClient (new ProtocolLogger ("smtp.log"))

Replace "Smtp" with Pop3 or Imap depending on what client you are having this issue with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants