org.subethamail.smtp.client
Class SMTPClient

java.lang.Object
  extended by org.subethamail.smtp.client.SMTPClient
Direct Known Subclasses:
SmartClient

public class SMTPClient
extends java.lang.Object

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
static class SMTPClient.Response
          Result of an SMTP exchange.
 
Constructor Summary
SMTPClient(java.lang.String host, int port)
          Establishes a connection to host and port and negotiate the initial EHLO exchange.
SMTPClient(java.lang.String host, int port, java.net.SocketAddress bindpoint)
          Establishes a connection to host and port from the specified local socket address and negotiate the initial EHLO exchange.
 
Method Summary
 void close()
          Logs but otherwise ignores errors
 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".
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SMTPClient

public SMTPClient(java.lang.String host,
                  int port)
           throws java.net.UnknownHostException,
                  java.io.IOException
Establishes a connection to host and port and negotiate the initial EHLO exchange.

Throws:
java.net.UnknownHostException - if the hostname cannot be resolved
java.io.IOException - if there is a problem connecting to the port

SMTPClient

public SMTPClient(java.lang.String host,
                  int port,
                  java.net.SocketAddress bindpoint)
           throws java.net.UnknownHostException,
                  java.io.IOException
Establishes a connection to host and port from the specified local socket address and negotiate the initial EHLO exchange.

Parameters:
bindpoint - the local socket address. If null, the system will pick up an ephemeral port and a valid local address.
Throws:
java.net.UnknownHostException - if the hostname cannot be resolved
java.io.IOException - if there is a problem connecting to the port
Method Detail

getHostPort

public java.lang.String getHostPort()
Returns:
a nice pretty description of who we are connected to

send

protected void send(java.lang.String msg)
             throws java.io.IOException
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:
java.io.IOException

receive

protected SMTPClient.Response receive()
                               throws java.io.IOException
Note that the response text comes back without trailing newlines.

Throws:
java.io.IOException

sendReceive

public SMTPClient.Response sendReceive(java.lang.String msg)
                                throws java.io.IOException
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:
java.io.IOException

receiveAndCheck

public void receiveAndCheck()
                     throws java.io.IOException,
                            SMTPException
If response is not success, throw an exception

Throws:
java.io.IOException
SMTPException

sendAndCheck

public void sendAndCheck(java.lang.String msg)
                  throws java.io.IOException,
                         SMTPException
If response is not success, throw an exception

Throws:
java.io.IOException
SMTPException

close

public void close()
Logs but otherwise ignores errors


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2006-2011. All Rights Reserved.