Skip to content

Commit

Permalink
Fixed SmtpClient to disconnect during Authenticate/Async on socket er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
jstedfast committed Jan 15, 2024
1 parent cb86726 commit d5770f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions MailKit/Net/Smtp/AsyncSmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ public override async Task AuthenticateAsync (SaslMechanism mechanism, Cancellat
response = await Stream.SendCommandAsync ("\r\n", cancellationToken).ConfigureAwait (false);
saslException = ex;
}
} catch {
Disconnect (uri.Host, uri.Port, GetSecureSocketOptions (uri), false);
throw;
} finally {
detector.IsAuthenticating = false;
}
Expand Down Expand Up @@ -367,6 +370,9 @@ public override async Task AuthenticateAsync (Encoding encoding, ICredentials cr
response = await Stream.SendCommandAsync ("\r\n", cancellationToken).ConfigureAwait (false);
saslException = ex;
}
} catch {
Disconnect (uri.Host, uri.Port, GetSecureSocketOptions (uri), false);
throw;
} finally {
detector.IsAuthenticating = false;
}
Expand Down
6 changes: 6 additions & 0 deletions MailKit/Net/Smtp/SmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,9 @@ public override void Authenticate (SaslMechanism mechanism, CancellationToken ca
response = Stream.SendCommand ("\r\n", cancellationToken);
saslException = ex;
}
} catch {
Disconnect (uri.Host, uri.Port, GetSecureSocketOptions (uri), false);
throw;
} finally {
detector.IsAuthenticating = false;
}
Expand Down Expand Up @@ -1142,6 +1145,9 @@ public override void Authenticate (Encoding encoding, ICredentials credentials,
response = Stream.SendCommand ("\r\n", cancellationToken);
saslException = ex;
}
} catch {
Disconnect (uri.Host, uri.Port, GetSecureSocketOptions (uri), false);
throw;
} finally {
detector.IsAuthenticating = false;
}
Expand Down

0 comments on commit d5770f9

Please sign in to comment.