Package org.subethamail.smtp.client
Class SMTPClient
java.lang.Object
org.subethamail.smtp.client.SMTPClient
- Direct Known Subclasses:
SmartClient
A very low level abstraction of the STMP stream which knows how to handle
the raw protocol for lines, whitespace, etc.
- Author:
- Jeff Schnitzer
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Logs but otherwise ignores errorsvoidEstablishes a connection to host and port.protected SocketReturns a new unconnected socket.Returns the local socket address.booleanReturns true if the client is connected to the server.protected SMTPClient.Responsereceive()Note that the response text comes back without trailing newlines.If response is not success, throw an exceptionprotected voidSends a message to the server, ie "HELO foo.example.com".sendAndCheck(String msg) If response is not success, throw an exceptionsendReceive(String msg) Sends a message to the server, ie "HELO foo.example.com".voidsetBindpoint(SocketAddress bindpoint) Sets the local socket address.voidsetHostPort(String hostPort) Sets the name of the remote MTA for informative purposes.toString()
-
Constructor Details
-
SMTPClient
public SMTPClient()Creates an unconnected client. -
SMTPClient
Establishes a connection to host and port.- Throws:
UnknownHostException- if the hostname cannot be resolvedIOException- if there is a problem connecting to the port
-
SMTPClient
public SMTPClient(String host, int port, SocketAddress bindpoint) throws UnknownHostException, IOException Establishes a connection to host and port from the specified local socket address.- Parameters:
bindpoint- the local socket address. If null, the system will pick up an ephemeral port and a valid local address.- Throws:
UnknownHostException- if the hostname cannot be resolvedIOException- if there is a problem connecting to the port
-
-
Method Details
-
connect
Establishes a connection to host and port.- Throws:
IOException- if there is a problem connecting to the port
-
createSocket
Returns a new unconnected socket.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.
-
isConnected
public boolean isConnected()Returns true if the client is connected to the server. -
send
Sends a message to the server, ie "HELO foo.example.com". A newline will be appended to the message.- Parameters:
msg- should not have any newlines- Throws:
IOException
-
receive
Note that the response text comes back without trailing newlines.- Throws:
IOException
-
sendReceive
Sends a message to the server, ie "HELO foo.example.com". A newline will be appended to the message.- Parameters:
msg- should not have any newlines- Returns:
- the response from the server
- Throws:
IOException
-
receiveAndCheck
If response is not success, throw an exception- Throws:
IOExceptionSMTPException
-
sendAndCheck
If response is not success, throw an exception- Throws:
IOExceptionSMTPException
-
close
public void close()Logs but otherwise ignores errors -
toString
-
setBindpoint
Sets the local socket address. If null, the system will pick up an ephemeral port and a valid local address. Default is null. -
getBindpoint
Returns the local socket address. -
setHostPort
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. -
getHostPort
- Returns:
- a nice pretty description of who we are connected to
-