uk.org.iscream.cms.util
Class Smtp

java.lang.Object
  extended byuk.org.iscream.cms.util.Smtp

public class Smtp
extends Object

The Simple Mail Transfer Protocol class. This class was inspired by the GJT.

Version:
$Id: Smtp.java,v 1.11 2003/02/05 14:27:59 tdb Exp $
Author:
$Author: tdb $

Field Summary
private  String _name
          This is the friendly identifier of the component this class is running in.
private  Socket _socket
          A reference to the Socket connected to the server
private  BufferedReader _socketIn
          A reference to the Reader connected to the server
private  PrintWriter _socketOut
          A reference to the Writer connected to the server
static String REVISION
          The current CVS revision of this class
 
Constructor Summary
Smtp(String server)
          Connects to the specified SMTP server, on the default (and standard) port 25.
Smtp(String server, int port)
          Connects to the specified SMTP server on a given port
 
Method Summary
 void close()
          Closes down the connection to the server
 PrintWriter getOutputStream()
          Gets the PrintWriter allowing data to be sent directly to the SMTP server
private  void init()
          Check the server sends a 220 message, and then send our HELO.
 void sendCommand(String cmd, int reply)
          Sends a command to the server
 void sendMessage()
          Completes and sends the current message
 void setSender(String sender)
          Specify who the message is from
 void setTo(String to)
          Specify who the message is to be sent to
 String toString()
          Overrides the Object.toString() method to provide clean logging (every class should have this).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
The current CVS revision of this class

See Also:
Constant Field Values

_name

private String _name
This is the friendly identifier of the component this class is running in. eg, a Filter may be called "filter1", If this class does not have an owning component, a name from the configuration can be placed here. This name could also be changed to null for utility classes.


_socketIn

private BufferedReader _socketIn
A reference to the Reader connected to the server


_socketOut

private PrintWriter _socketOut
A reference to the Writer connected to the server


_socket

private Socket _socket
A reference to the Socket connected to the server

Constructor Detail

Smtp

public Smtp(String server)
     throws IOException
Connects to the specified SMTP server, on the default (and standard) port 25.

Parameters:
server - The SMTP server to use
Throws:
IOException - if the connection to the server fails

Smtp

public Smtp(String server,
            int port)
     throws IOException
Connects to the specified SMTP server on a given port

Parameters:
server - The SMTP server to use
port - The SMTP server port
Throws:
IOException - if the connection to the server fails
Method Detail

close

public void close()
           throws IOException
Closes down the connection to the server

Throws:
IOException - if the command fails

setSender

public void setSender(String sender)
               throws IOException
Specify who the message is from

Parameters:
sender - the e-mail address of the sender
Throws:
IOException - if the command fails

setTo

public void setTo(String to)
           throws IOException
Specify who the message is to be sent to

Parameters:
to - the e-mail address of the receiver
Throws:
IOException - if the command fails

getOutputStream

public PrintWriter getOutputStream()
                            throws IOException
Gets the PrintWriter allowing data to be sent directly to the SMTP server

Returns:
a reference to the PrintWriter
Throws:
IOException - if the command fails

sendMessage

public void sendMessage()
                 throws IOException
Completes and sends the current message

Throws:
IOException - if the command fails

sendCommand

public void sendCommand(String cmd,
                        int reply)
                 throws IOException
Sends a command to the server

Parameters:
cmd - The command to send
reply - The expected reply-code
Throws:
IOException - if the incorrect response code is received

toString

public String toString()
Overrides the Object.toString() method to provide clean logging (every class should have this). This uses the uk.org.iscream.cms.server.util.FormatName class to format the toString()

Returns:
the name of this class and its CVS revision

init

private void init()
           throws IOException
Check the server sends a 220 message, and then send our HELO.

Throws:
IOException - if something goes wrong


Copyright © 2000-2003 i-scream. All Rights Reserved.