public class SMTPConnection extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static int |
AMBIGUOUS |
protected static String |
AUTH |
protected boolean |
continuation
If true, there are more responses to read.
|
protected static String |
DATA |
static int |
DEFAULT_PORT
The default SMTP port.
|
protected static String |
EHLO |
protected static String |
EXPN |
protected static String |
FINISH_DATA |
protected String |
greeting
The greeting message given by the server.
|
protected static String |
HELO |
protected static String |
HELP |
protected LineInputStream |
in
The input stream used to read responses from the server.
|
protected static int |
INFO |
static Logger |
logger
The logger used for SMTP protocol traces.
|
protected static String |
MAIL_FROM |
protected static String |
NOOP |
protected static int |
OK |
protected static int |
OK_NOT_LOCAL |
protected static int |
OK_UNVERIFIED |
protected CRLFOutputStream |
out
The output stream used to send commands to the server.
|
protected static String |
QUIT |
protected static String |
RCPT_TO |
protected static int |
READY |
protected String |
response
The last response message received from the server.
|
protected static String |
RSET |
protected static int |
SEND_DATA |
static Level |
SMTP_TRACE
The network trace level.
|
protected Socket |
socket
The underlying socket used for communicating with the server.
|
protected static String |
SP |
protected static String |
STARTTLS |
protected static String |
VRFY |
| Constructor and Description |
|---|
SMTPConnection(String host)
Creates a new connection to the specified host, using the default SMTP
port.
|
SMTPConnection(String host,
int port)
Creates a new connection to the specified host, using the specified
port.
|
SMTPConnection(String host,
int port,
int connectionTimeout,
int timeout)
Creates a new connection to the specified host, using the specified
port.
|
SMTPConnection(String host,
int port,
int connectionTimeout,
int timeout,
boolean secure,
TrustManager tm)
Creates a new connection to the specified host, using the specified
port.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
authenticate(String mechanism,
String username,
String password)
Authenticates the connection using the specified SASL mechanism,
username, and password.
|
OutputStream |
data()
Requests an output stream to write message data to.
|
List |
ehlo(String hostname)
Issues an EHLO command.
|
List |
expn(String address)
Returns a list of valid possibilities for the specified mailing list,
or null on failure.
|
boolean |
finishData()
Completes the DATA procedure.
|
protected int |
getAllResponses()
Returns the next response from the server.
|
String |
getGreeting()
Returns the server greeting message.
|
String |
getLastResponse()
Returns the text of the last response received from the server.
|
protected int |
getResponse()
Returns the next response from the server.
|
protected SSLSocketFactory |
getSSLSocketFactory(TrustManager tm)
Returns a configured SSLSocketFactory to use in creating new SSL
sockets.
|
boolean |
helo(String hostname)
Issues a HELO command.
|
List |
help(String arg)
Returns some useful information about the specified parameter.
|
boolean |
mailFrom(String reversePath,
ParameterList parameters)
Execute a MAIL command.
|
void |
noop()
Issues a NOOP command.
|
void |
quit()
Close the connection to the server.
|
boolean |
rcptTo(String forwardPath,
ParameterList parameters)
Execute a RCPT command.
|
void |
rset()
Aborts the current mail transaction.
|
protected void |
send(String command)
Send the specified command string to the server.
|
boolean |
starttls()
Negotiate TLS over the current connection.
|
boolean |
starttls(TrustManager tm)
Negotiate TLS over the current connection.
|
List |
vrfy(String address)
Returns a list of valid possibilities for the specified address, or
null on failure.
|
public static final Logger logger
public static final Level SMTP_TRACE
public static final int DEFAULT_PORT
protected static final String MAIL_FROM
protected static final String RCPT_TO
protected static final String SP
protected static final String DATA
protected static final String FINISH_DATA
protected static final String RSET
protected static final String VRFY
protected static final String EXPN
protected static final String HELP
protected static final String NOOP
protected static final String QUIT
protected static final String HELO
protected static final String EHLO
protected static final String AUTH
protected static final String STARTTLS
protected static final int INFO
protected static final int READY
protected static final int OK
protected static final int OK_NOT_LOCAL
protected static final int OK_UNVERIFIED
protected static final int SEND_DATA
protected static final int AMBIGUOUS
protected Socket socket
protected LineInputStream in
protected CRLFOutputStream out
protected String response
protected boolean continuation
protected final String greeting
public SMTPConnection(String host) throws IOException
host - the server hostnameIOExceptionpublic SMTPConnection(String host, int port) throws IOException
host - the server hostnameport - the port to connect toIOExceptionpublic SMTPConnection(String host, int port, int connectionTimeout, int timeout) throws IOException
host - the server hostnameport - the port to connect toconnectionTimeout - the connection timeout in millisecondstimeout - the I/O timeout in millisecondsIOExceptionpublic SMTPConnection(String host, int port, int connectionTimeout, int timeout, boolean secure, TrustManager tm) throws IOException
host - the server hostnameport - the port to connect toconnectionTimeout - the connection timeout in millisecondstimeout - the I/O timeout in millisecondssecure - true to create an SMTPS connectiontm - a trust manager used to check SSL certificates, or null to
use the defaultIOExceptionpublic String getGreeting()
public String getLastResponse()
public boolean mailFrom(String reversePath, ParameterList parameters) throws IOException
reversePath - the source mailbox(from address)parameters - optional ESMTP parametersIOExceptionpublic boolean rcptTo(String forwardPath, ParameterList parameters) throws IOException
forwardPath - the forward-path(recipient address)parameters - optional ESMTP parametersIOExceptionpublic OutputStream data() throws IOException
flush method must be called on the stream. Until then no
further methods should be called on the connection.
Immediately after this procedure is complete, finishData
must be called to complete the transfer and determine its success.IOExceptionpublic boolean finishData()
throws IOException
IOExceptiondata()public void rset()
throws IOException
IOExceptionpublic List vrfy(String address) throws IOException
address - a mailbox, or real name and mailboxIOExceptionpublic List expn(String address) throws IOException
address - a mailing list nameIOExceptionpublic List help(String arg) throws IOException
arg - the context of the query, or null for general informationIOExceptionpublic void noop()
throws IOException
IOExceptionpublic void quit()
throws IOException
IOExceptionpublic boolean helo(String hostname) throws IOException
hostname - the local host nameIOExceptionpublic List ehlo(String hostname) throws IOException
hostname - the local host nameIOExceptionprotected SSLSocketFactory getSSLSocketFactory(TrustManager tm) throws GeneralSecurityException
tm - an optional trust manager to useGeneralSecurityExceptionpublic boolean starttls()
throws IOException
IOExceptionpublic boolean starttls(TrustManager tm) throws IOException
tm - the custom trust manager to useIOExceptionpublic boolean authenticate(String mechanism, String username, String password) throws IOException
mechanism - a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername - the authentication principalpassword - the authentication credentialsIOExceptionprotected void send(String command) throws IOException
command - the command to sendIOExceptionprotected int getResponse()
throws IOException
IOExceptionprotected int getAllResponses()
throws IOException
IOExceptionCopyright © 2017. All rights reserved.