public class SMTPClient
extends java.lang.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(java.lang.String host,
int port)
Establishes a connection to host and port.
|
SMTPClient(java.lang.String host,
int port,
java.net.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(java.lang.String host,
int port)
Establishes a connection to host and port.
|
protected java.net.Socket |
createSocket()
Returns a new unconnected socket.
|
java.net.SocketAddress |
getBindpoint()
Returns the local socket address.
|
java.lang.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(java.lang.String msg)
Sends a message to the server, ie "HELO foo.example.com".
|
void |
sendAndCheck(java.lang.String msg)
If response is not success, throw an exception
|
SMTPClient.Response |
sendReceive(java.lang.String msg)
Sends a message to the server, ie "HELO foo.example.com".
|
void |
setBindpoint(java.net.SocketAddress bindpoint)
Sets the local socket address.
|
java.lang.String |
toString() |
public SMTPClient()
public SMTPClient(java.lang.String host, int port) throws java.net.UnknownHostException, java.io.IOException
java.net.UnknownHostException
- if the hostname cannot be resolvedjava.io.IOException
- if there is a problem connecting to the portpublic SMTPClient(java.lang.String host, int port, java.net.SocketAddress bindpoint) throws java.net.UnknownHostException, java.io.IOException
bindpoint
- the local socket address. If null, the system will pick up an
ephemeral port and a valid local address.java.net.UnknownHostException
- if the hostname cannot be resolvedjava.io.IOException
- if there is a problem connecting to the portpublic void connect(java.lang.String host, int port) throws java.io.IOException
java.io.IOException
- if there is a problem connecting to the portprotected java.net.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 java.lang.String getHostPort()
protected void send(java.lang.String msg) throws java.io.IOException
msg
- should not have any newlinesjava.io.IOException
protected SMTPClient.Response receive() throws java.io.IOException
java.io.IOException
public SMTPClient.Response sendReceive(java.lang.String msg) throws java.io.IOException
msg
- should not have any newlinesjava.io.IOException
public void receiveAndCheck() throws java.io.IOException, SMTPException
java.io.IOException
SMTPException
public void sendAndCheck(java.lang.String msg) throws java.io.IOException, SMTPException
java.io.IOException
SMTPException
public void close()
public java.lang.String toString()
toString
in class java.lang.Object
public void setBindpoint(java.net.SocketAddress bindpoint)
public java.net.SocketAddress getBindpoint()
Copyright © 2006–2014. All rights reserved.