in geronimo-javamail_1.3.1/geronimo-javamail_1.3.1_provider/src/main/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java [345:414]
protected boolean protocolConnect(String host, int port, String username, String password)
throws MessagingException {
// first check to see if we need to authenticate. If we need this, then
// we must have a username and
// password specified. Failing this may result in a user prompt to
// collect the information.
boolean mustAuthenticate = isProtocolPropertyTrue(MAIL_SMTP_AUTH);
// if we need to authenticate, and we don't have both a userid and
// password, then we fail this
// immediately. The Service.connect() method will try to obtain the user
// information and retry the
// connection one time.
if (mustAuthenticate && (username == null || password == null)) {
return false;
}
// Before we do anything, let's make sure that we succesfully received a host
if ( host == null ) {
host = DEFAULT_MAIL_HOST;
}
// if the port is defaulted, then see if we have something configured in
// the session.
// if not configured, we just use the default default.
if (port == -1) {
// take the default first.
port = defaultPort;
String configuredPort = getProtocolProperty(MAIL_SMTP_PORT);
if (configuredPort != null) {
port = Integer.parseInt(configuredPort);
}
}
if (debug) {
debugOut("Connecting to server " + host + ":" + port + " for user " + username);
}
try {
// create socket and connect to server.
getConnection(host, port, username, password);
// receive welcoming message
if (!getWelcome()) {
throw new MessagingException("Error in getting welcome msg");
}
// say hello
if (!sendHandshake()) {
throw new MessagingException("Error in saying EHLO to server");
}
// authenticate with the server, if necessary
if (!processAuthentication()) {
if (debug) {
debugOut("User authentication failure");
}
throw new AuthenticationFailedException("Error authenticating with server");
}
} catch (IOException e) {
if (debug) {
debugOut("I/O exception establishing connection", e);
}
throw new MessagingException("Connection error", e);
}
return true;
}