Class SmartClient

java.lang.Object
org.subethamail.smtp.client.SMTPClient
org.subethamail.smtp.client.SmartClient

public class SmartClient extends SMTPClient
A somewhat smarter abstraction of an SMTP client which doesn't require knowing anything about the nitty gritty of SMTP.
Author:
Jeff Schnitzer
  • Constructor Details

  • 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:
      connect in class SMTPClient
      Throws:
      IOException - if there is a problem connecting to the port
      SMTPException
      AuthenticationNotSupportedException
    • sendHeloOrEhlo

      protected void sendHeloOrEhlo() throws IOException, SMTPException
      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:
      IOException
      SMTPException
    • receive

      protected SMTPClient.Response receive() throws IOException
      Returns the server response. It takes note of a 421 response code, so QUIT will not be issued unnecessarily.
      Overrides:
      receive in class SMTPClient
      Throws:
      IOException
    • from

      public void from(String from) throws IOException, SMTPException
      Throws:
      IOException
      SMTPException
    • to

      public void to(String to) throws IOException, SMTPException
      Throws:
      IOException
      SMTPException
    • dataStart

      public void dataStart() throws IOException, SMTPException
      Prelude to writing data
      Throws:
      IOException
      SMTPException
    • dataWrite

      public void dataWrite(byte[] data, int numBytes) throws IOException
      Actually write some data
      Throws:
      IOException
    • dataEnd

      public void dataEnd() throws IOException, SMTPException
      Last step after writing data
      Throws:
      IOException
      SMTPException
    • 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.

      See Also:
    • 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

      public Map<String,String> 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

      public void setHeloHost(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. This has no default and is required.
    • getHeloHost

      public String getHeloHost()
      Returns the HELO name of this system.
    • getAuthenticator

      public Authenticator getAuthenticator()
      Returns the Authenticator object, which is used to authenticate this client to the server, or null, if no authentication is required.
    • setAuthenticator

      public void setAuthenticator(Authenticator authenticator)
      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.