public class SMTPClient extends Object
Modifier and Type | Class and Description |
---|---|
static class |
SMTPClient.Response
Result of an SMTP exchange.
|
Constructor and Description |
---|
SMTPClient()
Creates an unconnected client.
|
SMTPClient(String host,
int port)
Establishes a connection to host and port.
|
SMTPClient(String host,
int port,
SocketAddress bindpoint)
Establishes a connection to host and port from the specified local socket
address.
|
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.
|
protected Socket |
createSocket()
Returns a new unconnected socket.
|
SocketAddress |
getBindpoint()
Returns the local socket address.
|
String |
getHostPort() |
protected SMTPClient.Response |
receive()
Note that the response text comes back without trailing newlines.
|
void |
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".
|
void |
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".
|
void |
setBindpoint(SocketAddress bindpoint)
Sets the local socket address.
|
String |
toString() |
public SMTPClient()
public SMTPClient(String host, int port) throws UnknownHostException, IOException
UnknownHostException
- if the hostname cannot be resolvedIOException
- if there is a problem connecting to the portpublic SMTPClient(String host, int port, SocketAddress bindpoint) throws UnknownHostException, IOException
bindpoint
- the local socket address. If null, the system will pick up an
ephemeral port and a valid local address.UnknownHostException
- if the hostname cannot be resolvedIOException
- if there is a problem connecting to the portpublic 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 String getHostPort()
protected void send(String msg) throws IOException
msg
- should not have any newlinesIOException
protected SMTPClient.Response receive() throws IOException
IOException
public SMTPClient.Response sendReceive(String msg) throws IOException
msg
- should not have any newlinesIOException
public void receiveAndCheck() throws IOException, SMTPException
IOException
SMTPException
public void sendAndCheck(String msg) throws IOException, SMTPException
IOException
SMTPException
public void close()
public void setBindpoint(SocketAddress bindpoint)
public SocketAddress getBindpoint()
Copyright © 2006–2018. All rights reserved.