public class SMTPConnection
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static int |
AMBIGUOUS |
protected static java.lang.String |
AUTH |
protected static java.lang.String |
DATA |
static int |
DEFAULT_PORT
The default SMTP port.
|
static int |
DEFAULT_SSL_PORT
The default SMTPS port.
|
protected static java.lang.String |
EHLO |
protected static java.lang.String |
EXPN |
protected static java.lang.String |
FINISH_DATA |
protected static java.lang.String |
HELO |
protected static java.lang.String |
HELP |
protected static int |
INFO |
protected static java.lang.String |
MAIL_FROM |
protected static java.lang.String |
NOOP |
protected static int |
OK |
protected static int |
OK_NOT_LOCAL |
protected static int |
OK_UNVERIFIED |
protected static java.lang.String |
QUIT |
protected static java.lang.String |
RCPT_TO |
protected static int |
READY |
protected static java.lang.String |
RSET |
protected static int |
SEND_DATA |
static java.util.logging.Level |
SMTP_TRACE
The network trace level.
|
protected static java.lang.String |
SP |
protected static java.lang.String |
STARTTLS |
protected static java.lang.String |
VRFY |
| Constructor and Description |
|---|
SMTPConnection (java.lang.String host)
Creates a new connection to the specified host, using the default SMTP
port.
|
SMTPConnection (java.lang.String host,
int port)
Creates a new connection to the specified host, using the specified
port.
|
SMTPConnection (java.lang.String host,
int port,
int connectionTimeout,
int timeout)
Creates a new connection to the specified host, using the specified
port.
|
SMTPConnection (java.lang.String host,
int port,
int connectionTimeout,
int timeout,
boolean secure,
javax.net.ssl.TrustManager tm)
Creates a new connection to the specified host, using the specified
port.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
authenticate (java.lang.String mechanism,
java.lang.String username,
java.lang.String password)
Authenticates the connection using the specified SASL mechanism,
username, and password.
|
java.io.OutputStream |
data ()
Requests an output stream to write message data to.
|
java.util.List<java.lang.String> |
ehlo (java.lang.String hostname)
Issues an EHLO command.
|
java.util.List<java.lang.String> |
expn (java.lang.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.
|
java.lang.String |
getGreeting ()
Returns the server greeting message.
|
java.lang.String |
getLastResponse ()
Returns the text of the last response received from the server.
|
java.util.logging.Logger |
getLogger ()
Returns the logger used by this connection for debug output.
|
protected int |
getResponse ()
Returns the next response from the server.
|
protected javax.net.ssl.SSLSocketFactory |
getSSLSocketFactory (javax.net.ssl.TrustManager tm)
Returns a configured SSLSocketFactory to use in creating new SSL
sockets.
|
boolean |
helo (java.lang.String hostname)
Issues a HELO command.
|
java.util.List<java.lang.String> |
help (java.lang.String arg)
Returns some useful information about the specified parameter.
|
boolean |
mailFrom (java.lang.String reversePath,
ParameterList parameters)
Execute a MAIL command.
|
void |
noop ()
Issues a NOOP command.
|
void |
quit ()
Close the connection to the server.
|
boolean |
rcptTo (java.lang.String forwardPath,
ParameterList parameters)
Execute a RCPT command.
|
void |
rset ()
Aborts the current mail transaction.
|
protected void |
send (java.lang.String command)
Send the specified command string to the server.
|
boolean |
starttls ()
Negotiate TLS over the current connection.
|
boolean |
starttls (javax.net.ssl.TrustManager tm)
Negotiate TLS over the current connection.
|
java.util.List<java.lang.String> |
vrfy (java.lang.String address)
Returns a list of valid possibilities for the specified address, or
null on failure.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpublic static final java.util.logging.Level SMTP_TRACE
public static final int DEFAULT_PORT
public static final int DEFAULT_SSL_PORT
protected static final java.lang.String MAIL_FROM
protected static final java.lang.String RCPT_TO
protected static final java.lang.String SP
protected static final java.lang.String DATA
protected static final java.lang.String FINISH_DATA
protected static final java.lang.String RSET
protected static final java.lang.String VRFY
protected static final java.lang.String EXPN
protected static final java.lang.String HELP
protected static final java.lang.String NOOP
protected static final java.lang.String QUIT
protected static final java.lang.String HELO
protected static final java.lang.String EHLO
protected static final java.lang.String AUTH
protected static final java.lang.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
public SMTPConnection(java.lang.String host)
host - the server hostnamepublic SMTPConnection(java.lang.String host, int port)
host - the server hostnameport - the port to connect topublic SMTPConnection(java.lang.String host, int port, int connectionTimeout, int timeout)
host - the server hostnameport - the port to connect toconnectionTimeout - the connection timeout in millisecondstimeout - the I/O timeout in millisecondspublic SMTPConnection(java.lang.String host, int port, int connectionTimeout, int timeout, boolean secure, javax.net.ssl.TrustManager tm)
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 defaultpublic java.util.logging.Logger getLogger()
public java.lang.String getGreeting()
public java.lang.String getLastResponse()
public boolean mailFrom(java.lang.String reversePath, ParameterList parameters) throws java.io.IOException
reversePath - the source mailbox(from address)parameters - optional ESMTP parametersjava.io.IOExceptionpublic boolean rcptTo(java.lang.String forwardPath, ParameterList parameters) throws java.io.IOException
forwardPath - the forward-path(recipient address)parameters - optional ESMTP parametersjava.io.IOExceptionpublic java.io.OutputStream data() throws java.io.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.java.io.IOExceptionpublic boolean finishData() throws java.io.IOException
java.io.IOExceptiondata() public void rset() throws java.io.IOException
java.io.IOExceptionpublic java.util.List<java.lang.String> vrfy(java.lang.String address) throws java.io.IOException
address - a mailbox, or real name and mailboxjava.io.IOExceptionpublic java.util.List<java.lang.String> expn(java.lang.String address) throws java.io.IOException
address - a mailing list namejava.io.IOExceptionpublic java.util.List<java.lang.String> help(java.lang.String arg) throws java.io.IOException
arg - the context of the query, or null for general informationjava.io.IOExceptionpublic void noop() throws java.io.IOException
java.io.IOExceptionpublic void quit() throws java.io.IOException
java.io.IOExceptionpublic boolean helo(java.lang.String hostname) throws java.io.IOException
hostname - the local host namejava.io.IOExceptionpublic java.util.List<java.lang.String> ehlo(java.lang.String hostname) throws java.io.IOException
hostname - the local host namejava.io.IOExceptionprotected javax.net.ssl.SSLSocketFactory getSSLSocketFactory(javax.net.ssl.TrustManager tm) throws java.security.GeneralSecurityException
tm - an optional trust manager to usejava.security.GeneralSecurityExceptionpublic boolean starttls() throws java.io.IOException
java.io.IOExceptionpublic boolean starttls(javax.net.ssl.TrustManager tm) throws java.io.IOException
tm - the custom trust manager to usejava.io.IOExceptionpublic boolean authenticate(java.lang.String mechanism, java.lang.String username, java.lang.String password) throws java.io.IOException
mechanism - a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername - the authentication principalpassword - the authentication credentialsjava.io.IOExceptionprotected void send(java.lang.String command) throws java.io.IOException
command - the command to sendjava.io.IOExceptionprotected int getResponse() throws java.io.IOException
java.io.IOExceptionprotected int getAllResponses() throws java.io.IOException
java.io.IOException