Skip to content

Commit

Permalink
Don't wait for banner message from SMTP server after STARTTLS negotia…
Browse files Browse the repository at this point in the history
…tion

According to RFC 2847 section 5.2, SMTP server won't send banner message
again after STARTTLS negotiation. The original code will hang until
SMTP server kicks it off due to timeout and can't send email with
STARTTLS enabled, aka. sendemail.smtpEncryption = tls.

Bug: Issue 1397
Change-Id: I5822e7f1aae0e13ea082964702bde96132f73e2c
  • Loading branch information
Dieken committed May 24, 2012
1 parent e1e5ddd commit 34d4d19
Showing 1 changed file with 20 additions and 1 deletion.
Expand Up @@ -18,7 +18,11 @@

import org.apache.commons.codec.binary.Base64;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.SocketException;
import java.security.InvalidKeyException;
Expand Down Expand Up @@ -50,7 +54,22 @@ public boolean startTLS(final String hostname, final int port, final boolean ver
}

_socket_ = sslFactory(verify).createSocket(_socket_, hostname, port, true);
_connectAction_();

// XXX: Can't call _connectAction_() because SMTP server doesn't
// give banner information again after STARTTLS, thus SMTP._connectAction_()
// will wait on __getReply() forever, see source code of commons-net-2.2.
//
// The lines below are copied from SocketClient._connectAction_() and
// SMTP._connectAction_() in commons-net-2.2.
_socket_.setSoTimeout(_timeout_);
_input_ = _socket_.getInputStream();
_output_ = _socket_.getOutputStream();
_reader =
new BufferedReader(new InputStreamReader(_input_,
UTF_8));
_writer =
new BufferedWriter(new OutputStreamWriter(_output_,
UTF_8));
return true;
}

Expand Down

0 comments on commit 34d4d19

Please sign in to comment.