Package org.subethamail.smtp.client
Class SmartClient
java.lang.Object
org.subethamail.smtp.client.SMTPClient
org.subethamail.smtp.client.SmartClient
A somewhat smarter abstraction of an SMTP client which doesn't require knowing
anything about the nitty gritty of SMTP.
- Author:
- Jeff Schnitzer
-
Nested Class Summary
Nested classes/interfaces inherited from class org.subethamail.smtp.client.SMTPClient
SMTPClient.Response -
Constructor Summary
ConstructorsConstructorDescriptionCreates an unconnected client.SmartClient(String host, int port, String myHost) Connects to the specified server and issues the initial HELO command.SmartClient(String host, int port, SocketAddress bindpoint, String myHost) Connects to the specified server and issues the initial HELO command. -
Method Summary
Modifier and TypeMethodDescriptionvoidConnects to the specified server and issues the initial HELO command.voiddataEnd()Last step after writing datavoidPrelude to writing datavoiddataWrite(byte[] data, int numBytes) Actually write some datavoidReturns the Authenticator object, which is used to authenticate this client to the server, or null, if no authentication is required.Returns the SMTP extensions supported by the server.Returns the HELO name of this system.intvoidquit()Quit and close down the connection.protected SMTPClient.Responsereceive()Returns the server response.protected voidSends the EHLO command, or HELO if EHLO is not supported, and saves the list of SMTP extensions which are supported by the server.booleansentFrom()booleansentTo()voidsetAuthenticator(Authenticator authenticator) Sets the Authenticator object which will be called after the EHLO command to authenticate this client to the server.voidsetHeloHost(String myHost) Sets the domain name or address literal of this system, which name will be sent to the server in the parameter of the HELO and EHLO commands.voidMethods inherited from class org.subethamail.smtp.client.SMTPClient
close, createSocket, getBindpoint, getHostPort, isConnected, receiveAndCheck, send, sendAndCheck, sendReceive, setBindpoint, setHostPort, toString
-
Constructor Details
-
SmartClient
public SmartClient()Creates an unconnected client. -
SmartClient
public SmartClient(String host, int port, String myHost) throws UnknownHostException, IOException, SMTPException Connects to the specified server and issues the initial HELO command.- Throws:
UnknownHostException- if problem looking up hostnameSMTPException- if problem reported by the serverIOException- if problem communicating with host
-
SmartClient
public SmartClient(String host, int port, SocketAddress bindpoint, String myHost) throws UnknownHostException, IOException, SMTPException Connects to the specified server and issues the initial HELO command.- Throws:
UnknownHostException- if problem looking up hostnameSMTPException- if problem reported by the serverIOException- if problem communicating with host
-
-
Method Details
-
connect
public void connect(String host, int port) throws SMTPException, AuthenticationNotSupportedException, IOException Connects to the specified server and issues the initial HELO command. It gracefully closes the connection if it could be established but subsequently it fails or if the server does not accept messages.- Overrides:
connectin classSMTPClient- Throws:
IOException- if there is a problem connecting to the portSMTPExceptionAuthenticationNotSupportedException
-
sendHeloOrEhlo
Sends the EHLO command, or HELO if EHLO is not supported, and saves the list of SMTP extensions which are supported by the server.- Throws:
IOExceptionSMTPException
-
receive
Returns the server response. It takes note of a 421 response code, so QUIT will not be issued unnecessarily.- Overrides:
receivein classSMTPClient- Throws:
IOException
-
from
- Throws:
IOExceptionSMTPException
-
to
- Throws:
IOExceptionSMTPException
-
dataStart
Prelude to writing data- Throws:
IOExceptionSMTPException
-
dataWrite
Actually write some data- Throws:
IOException
-
dataEnd
Last step after writing data- Throws:
IOExceptionSMTPException
-
quit
public void quit()Quit and close down the connection. Ignore any errors.It still closes the connection, but it does not send the QUIT command if a 421 Service closing transmission channel is received previously. In these cases QUIT would fail anyway.
-
sentFrom
public boolean sentFrom()- Returns:
- true if we have already specified from()
-
sentTo
public boolean sentTo()- Returns:
- true if we have already specified to()
-
getRecipientCount
public int getRecipientCount()- Returns:
- the number of recipients that have been accepted by the server
-
getExtensions
Returns the SMTP extensions supported by the server.- Returns:
- the extension map. Key is the extension keyword in upper case, value is the unparsed string of extension parameters.
-
setHeloHost
Sets the domain name or address literal of this system, which name will be sent to the server in the parameter of the HELO and EHLO commands. This has no default and is required. -
getHeloHost
Returns the HELO name of this system. -
getAuthenticator
Returns the Authenticator object, which is used to authenticate this client to the server, or null, if no authentication is required. -
setAuthenticator
Sets the Authenticator object which will be called after the EHLO command to authenticate this client to the server. The default is that no authentication will happen.
-