Skip to content

Commit

Permalink
Improve SMTP error message with server returns bad greeting - fix #387
Browse files Browse the repository at this point in the history
  • Loading branch information
bshannon committed Feb 15, 2020
1 parent c29f6e5 commit 2b6ceed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions doc/release/CHANGES.txt
Expand Up @@ -24,6 +24,7 @@ longer available.
----------------------------
The following bugs have been fixed in the 1.6.5 release.

E 387 misleading SMTP error message when server returns bad greeting
E 398 Don't enforce dot rules for quoted-string in local-part
E 399 NPE com.sun.mail.imap.protocol.BODY.getOrigin() since 1.6.4
E 400 finalizecleanclose false can send commands causing unhandled exception
Expand Down
59 changes: 30 additions & 29 deletions mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -2170,34 +2170,35 @@ private void openServer(String host, int port)

int r = -1;
if ((r = readServerResponse()) != 220) {
try {
if (quitOnSessionReject) {
sendCommand("QUIT");
if (quitWait) {
int resp = readServerResponse();
if (resp != 221 && resp != -1 &&
logger.isLoggable(Level.FINE))
logger.fine("QUIT failed with " + resp);
}
}
} catch (Exception e) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, "QUIT failed", e);
} finally {
serverSocket.close();
serverSocket = null;
serverOutput = null;
serverInput = null;
lineInputStream = null;
}
if (logger.isLoggable(Level.FINE))
logger.fine("could not connect to host \"" +
host + "\", port: " + port +
", response: " + r);
throw new MessagingException(
"Could not connect to SMTP host: " + host +
", port: " + port +
", response: " + r);
String failResponse = lastServerResponse;
try {
if (quitOnSessionReject) {
sendCommand("QUIT");
if (quitWait) {
int resp = readServerResponse();
if (resp != 221 && resp != -1 &&
logger.isLoggable(Level.FINE))
logger.fine("QUIT failed with " + resp);
}
}
} catch (Exception e) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, "QUIT failed", e);
} finally {
serverSocket.close();
serverSocket = null;
serverOutput = null;
serverInput = null;
lineInputStream = null;
}
if (logger.isLoggable(Level.FINE))
logger.fine("got bad greeting from host \"" +
host + "\", port: " + port +
", response: " + failResponse);
throw new MessagingException(
"Got bad greeting from SMTP host: " + host +
", port: " + port +
", response: " + failResponse);
} else {
if (logger.isLoggable(Level.FINE))
logger.fine("connected to host \"" +
Expand Down

0 comments on commit 2b6ceed

Please sign in to comment.