public class SMTPClient extends Object implements AutoCloseable
| Modifier and Type | Class and Description |
|---|---|
static class |
SMTPClient.Response
Result of an SMTP exchange.
|
| Modifier and Type | Field and Description |
|---|---|
static long |
RECEIVE_AND_CHECK_PAUSE_MS
This field is temporary only till SmartClient builder is created.
|
| Constructor and Description |
|---|
SMTPClient()
Establishes a connection to host and port.
|
SMTPClient(Optional<SocketAddress> bindpoint,
Optional<String> hostPortName)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Logs but otherwise ignores errors
|
void |
connect(String host,
int port)
Establishes a connection to host and port.
|
static SMTPClient |
createAndConnect(String host,
int port) |
static SMTPClient |
createAndConnect(String host,
int port,
Optional<String> hostPortName) |
protected Socket |
createSocket()
Returns a new unconnected socket.
|
String |
getHostPort() |
SocketAddress |
getLocalSocketAddress()
Returns the local socket address.
|
boolean |
isConnected()
Returns true if the client is connected to the server.
|
protected SMTPClient.Response |
receive()
Note that the response text comes back without trailing newlines.
|
SMTPClient.Response |
receiveAndCheck()
If response is not success, throw an exception
|
protected void |
send(String msg)
Sends a message to the server, ie "HELO foo.example.com".
|
SMTPClient.Response |
sendAndCheck(String msg)
If response is not success, throw an exception
|
SMTPClient.Response |
sendReceive(String msg)
Sends a message to the server, ie "HELO foo.example.com".
|
String |
toString() |
public static final long RECEIVE_AND_CHECK_PAUSE_MS
public SMTPClient()
public SMTPClient(Optional<SocketAddress> bindpoint, Optional<String> hostPortName)
bindpoint - the local socket address. If empty, the system will pick up an
ephemeral port and a valid local address.hostPortName - Sets the name of the remote MTA for informative purposes.
Default is host:port, where host and port are the values which
were used to open the TCP connection to the server, as they
were passed to the connect method.public static SMTPClient createAndConnect(String host, int port) throws UnknownHostException, IOException
UnknownHostExceptionIOExceptionpublic static SMTPClient createAndConnect(String host, int port, Optional<String> hostPortName) throws UnknownHostException, IOException
UnknownHostExceptionIOExceptionpublic void connect(String host, int port) throws IOException
IOException - if there is a problem connecting to the portprotected Socket createSocket()
Implementation notice for subclasses: This function is called by the constructors which open the connection immediately. In these cases the subclass is not yet initialized, therefore subclasses overriding this function shouldn't use those constructors.
public boolean isConnected()
protected void send(String msg) throws IOException
msg - should not have any newlinesIOExceptionprotected SMTPClient.Response receive() throws IOException
IOExceptionpublic SMTPClient.Response sendReceive(String msg) throws IOException
msg - should not have any newlinesIOExceptionpublic SMTPClient.Response receiveAndCheck() throws IOException, SMTPException
IOExceptionSMTPExceptionpublic SMTPClient.Response sendAndCheck(String msg) throws IOException, SMTPException
IOExceptionSMTPExceptionpublic void close()
close in interface AutoCloseablepublic SocketAddress getLocalSocketAddress()
public String getHostPort()
Copyright © 2006–2024. All rights reserved.