org.subethamail.smtp.client
Class SmartClient

java.lang.Object
  extended by org.subethamail.smtp.client.SMTPClient
      extended by 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

Nested Class Summary
 
Nested classes/interfaces inherited from class org.subethamail.smtp.client.SMTPClient
SMTPClient.Response
 
Constructor Summary
SmartClient()
          Creates an unconnected client.
SmartClient(String host, int port, SocketAddress bindpoint, String myHost)
          Connects to the specified server and issues the initial HELO command.
SmartClient(String host, int port, String myHost)
          Connects to the specified server and issues the initial HELO command.
 
Method Summary
 void connect(String host, int port)
          Connects to the specified server and issues the initial HELO command.
 void dataEnd()
          Last step after writing data
 void dataStart()
          Prelude to writing data
 void dataWrite(byte[] data, int numBytes)
          Actually write some data
 void from(String from)
           
 String getHeloHost()
          Returns the HELO name of this system.
 int getRecipientCount()
           
 void quit()
          Quit and close down the connection.
protected  SMTPClient.Response receive()
          Returns the server response.
 boolean sentFrom()
           
 boolean sentTo()
           
 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.
 void to(String to)
           
 
Methods inherited from class org.subethamail.smtp.client.SMTPClient
close, createSocket, getBindpoint, getHostPort, receiveAndCheck, send, sendAndCheck, sendReceive, setBindpoint, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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 hostname
SMTPException - if problem reported by the server
IOException - 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 hostname
SMTPException - if problem reported by the server
IOException - if problem communicating with host
Method Detail

connect

public void connect(String host,
                    int port)
             throws IOException,
                    SMTPException
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

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:
RFC 5321 Terminating Sessions and Connections

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

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.



Copyright © 2006-2012. All Rights Reserved.