All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class msch.smtp.smtp

java.lang.Object
   |
   +----msch.smtp.smtp

public class smtp
extends Object
This is a simple smtp class which provides all the necessary functions to send mail from within a JAVA program. It was inspired by the euqally simple pop3 class from J. Thomas


Variable Index

 o _StatusOK
 o debugOn
 o Host
 o LastCmd
 o Port
 o replyTo
 o Server
 o ServerInputStream
 o Version
 o X_Mailer

Constructor Index

 o smtp()

Method Index

 o close()
This method closes the socket and must be called after mail has been sent and after the endCommunication command has been issued.
 o connect()
Connects to a host and port specified during initialization of the class.
 o connect(String)
Makes a connection to the host specified.
 o connect(String, int)
Makes a connection to the host and port specified.
 o endCommunication()
Signals to the host that no more mail data is going to be sent.
 o help()
Requests a help string from the host.
 o noop()
Does not do anything but keeps the host "alive" which will reply with a "250" answer.
 o reset()
If this command is send before the endCommunication command, then the mail is not sent and all the buffers in the host are reset.
 o sendData(String)
Sends data contained in a string.
 o sendData(String, String)
Sends data contained in a string.
 o sendFromName(String)
This is the first command to be sent after the host has accepted the startCommunication() command.
 o sendToName(String)
This must be issued right after the sendFromName() command.
 o setDebugOn(boolean)
Switches the class into debug mode
 o setReplyTo(String)
Sets the default ReplyTo field for the mail header
 o setXMailer(String)
Sets the X-Mailer variable which is send with the mail header param mailer = the name of the program using this class lib
 o smtp()
Constructs the smtp client.
 o smtp(String, int)
Constructs the smtp client.
 o startCommunication()
This method sends a "HELO" command to the host, after which the mail transfer may start.

Variables

 o Version
 protected String Version
 o LastCmd
 protected String LastCmd
 o Host
 protected String Host
 o Port
 protected int Port
 o Server
 protected Socket Server
 o ServerInputStream
 protected BufferedReader ServerInputStream
 o _StatusOK
 protected boolean _StatusOK
 o X_Mailer
 protected String X_Mailer
 o replyTo
 protected String replyTo
 o debugOn
 public boolean debugOn

Constructors

 o smtp
 public smtp()

Methods

 o smtp
 public void smtp(String host,
                  int port)
Constructs the smtp client.

Parameters:
host - = host's IP address
port - = host's smtp port (usually 25)
 o smtp
 public void smtp()
Constructs the smtp client. With a port initialized to 25

 o setXMailer
 public void setXMailer(String mailer)
Sets the X-Mailer variable which is send with the mail header param mailer = the name of the program using this class lib

 o setReplyTo
 public void setReplyTo(String replyTo)
Sets the default ReplyTo field for the mail header

Parameters:
replyTo - = reply to address
 o connect
 public smtpStatus connect(String host)
Makes a connection to the host specified.

Parameters:
host - = IP address of the host
 o connect
 public smtpStatus connect(String host,
                           int port)
Makes a connection to the host and port specified.

Parameters:
host - = IP address of the host
 o connect
 public synchronized smtpStatus connect()
Connects to a host and port specified during initialization of the class. This class opens the communication channel and if the host accepts the link it will answer with "220". And appropriate status is returned to indicate to the calling program what to do next.

 o close
 public synchronized smtpStatus close()
This method closes the socket and must be called after mail has been sent and after the endCommunication command has been issued.

 o startCommunication
 public synchronized smtpStatus startCommunication()
This method sends a "HELO" command to the host, after which the mail transfer may start. If the host is ready it will send a "25" response

 o endCommunication
 public synchronized smtpStatus endCommunication()
Signals to the host that no more mail data is going to be sent. The host should acknowledge with a "221" command.

 o sendFromName
 public synchronized smtpStatus sendFromName(String from)
This is the first command to be sent after the host has accepted the startCommunication() command.

Parameters:
from - = the senders (your) address.
 o sendToName
 public synchronized smtpStatus sendToName(String to)
This must be issued right after the sendFromName() command. This command may be issued repeatedly for every receiver !

Parameters:
to - = the receivers address.
 o sendData
 public synchronized smtpStatus sendData(String data)
Sends data contained in a string. The complete message must be contained in the string ! It is not possible to send line by line !

Parameters:
data - = String containing the mail message
 o sendData
 public synchronized smtpStatus sendData(String Subject,
                                         String data)
Sends data contained in a string. And prefixes a Subject line to it. The complete message must be contained in the string ! It is not possible to send line by line !

Parameters:
Subject - = String containing the subject line
data - = String containing the complete mail message
 o reset
 public synchronized smtpStatus reset()
If this command is send before the endCommunication command, then the mail is not sent and all the buffers in the host are reset. This command should always be sent when you have received a false status from any of the other mail commands.

 o noop
 public synchronized smtpStatus noop()
Does not do anything but keeps the host "alive" which will reply with a "250" answer.

 o help
 public synchronized smtpStatus help()
Requests a help string from the host. Note: not all hosts have implemented this command. Which will result in a "502" command not implemented.

 o setDebugOn
 public void setDebugOn(boolean OnOff)
Switches the class into debug mode

Parameters:
OnOff - = boolean flag

All Packages  Class Hierarchy  This Package  Previous  Next  Index