Qsmtp
Class Qsmtp

java.lang.Object
  |
  +--Qsmtp.Qsmtp
All Implemented Interfaces:
java.lang.Runnable

public class Qsmtp
extends java.lang.Object
implements java.lang.Runnable

SMTP mailer class, used to send email messages (with optional HTML MIME attachments) through direct TCP/IP communication with Internet SMTP mail servers.

The Qsmtp constructors take an address for a SMTP mail server, and all messages subsequently sent out by the Qstmp object are handled by that SMTP server.

Once created, a Qsmtp object can be used to send any number of messages through that mail server. Each call to sendmsg or sendHTMLmsg opens a separate SMTP connection to the designated mail server and transmits a single message.

Because this class opens a socket to a potentially remote TCP/IP server, this class may not function properly when used within an applet.


Field Summary
private  java.net.InetAddress address
           
private  java.lang.Thread backgroundThread
           
(package private) static boolean debug
           
(package private) static int DEFAULT_PORT
           
(package private) static java.lang.String EOL
           
private  java.lang.String hostid
           
private  int port
           
private  java.util.Vector queuedMessages
           
private  boolean threaded
           
 
Constructor Summary
Qsmtp(java.net.InetAddress address)
           
Qsmtp(java.net.InetAddress address, int port)
           
Qsmtp(java.lang.String hostid)
           
Qsmtp(java.lang.String hostid, int port)
           
 
Method Summary
private  void dispatchMessage(Qsmtp.messageObject msgObj)
          This method handles the actual mail-out
static java.lang.String formatDate(java.util.Date date)
          This method returns a properly mail-formatted date string.
 void goThreaded()
          After this method is called, all further sendmsg() calls will not directly send mail themselves, but will rather queue the mail for sending by a back-ground thread.
 void run()
          Main worker routine for the background thread which handles mail-outs.
 void sendHTMLmsg(java.lang.String from_address, java.util.Vector to_addresses, java.lang.String subject, java.lang.String htmlBody, java.lang.String htmlFilename, java.lang.String textBody)
          Sends a message with a MIME-attached HTML message
 void sendmsg(java.lang.String from_address, java.util.Vector to_addresses, java.lang.String subject, java.lang.String message)
          Sends a plain ASCII mail message
 void sendmsg(java.lang.String from_address, java.util.Vector to_addresses, java.lang.String subject, java.lang.String message, java.util.Vector extraHeaders)
          Sends a mail message with some custom-specified envelope headers.
 void stopThreaded()
          Calling this method turns off the background thread and returns Qsmtp to normal blocking operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

static final boolean debug
See Also:
Constant Field Values

DEFAULT_PORT

static final int DEFAULT_PORT
See Also:
Constant Field Values

EOL

static final java.lang.String EOL
See Also:
Constant Field Values

hostid

private java.lang.String hostid

address

private java.net.InetAddress address

port

private int port

queuedMessages

private java.util.Vector queuedMessages

threaded

private boolean threaded

backgroundThread

private java.lang.Thread backgroundThread
Constructor Detail

Qsmtp

public Qsmtp(java.lang.String hostid)

Qsmtp

public Qsmtp(java.lang.String hostid,
             int port)

Qsmtp

public Qsmtp(java.net.InetAddress address)

Qsmtp

public Qsmtp(java.net.InetAddress address,
             int port)
Method Detail

goThreaded

public void goThreaded()

After this method is called, all further sendmsg() calls will not directly send mail themselves, but will rather queue the mail for sending by a back-ground thread.

One result of this is that after this is called, the sendmsg() methods will never throw Protcol or IO Exceptions, and no success/failure results will be returned.

If this method is called while an previous background thread that was ordered to stop by stopThreaded() is still shutting down, this method will block until the old background thread dies and the new background thread can be established.


stopThreaded

public void stopThreaded()

Calling this method turns off the background thread and returns Qsmtp to normal blocking operation.


sendmsg

public void sendmsg(java.lang.String from_address,
                    java.util.Vector to_addresses,
                    java.lang.String subject,
                    java.lang.String message)
             throws java.io.IOException

Sends a plain ASCII mail message

Parameters:
from_address - Who is sending this message?
to_addresses - Vector of string addresses to send this message to
subject - Subject for this message
message - The text for the mail message
Throws:
java.io.IOException

sendHTMLmsg

public void sendHTMLmsg(java.lang.String from_address,
                        java.util.Vector to_addresses,
                        java.lang.String subject,
                        java.lang.String htmlBody,
                        java.lang.String htmlFilename,
                        java.lang.String textBody)
                 throws java.io.IOException

Sends a message with a MIME-attached HTML message

In a perfect world, we'd do a generic MIME-capable mail system here, but as it is, we only support HTML.

Parameters:
from_address - Who is sending this message?
to_addresses - Vector of string addresses to send this message to
subject - Subject for this message
htmlBody - A string containing the HTML document to be sent
htmlFilename - The name to label the HTML document with, will show up in mail clients
textBody - The text for the non-HTML part of the mail message
Throws:
java.io.IOException

sendmsg

public void sendmsg(java.lang.String from_address,
                    java.util.Vector to_addresses,
                    java.lang.String subject,
                    java.lang.String message,
                    java.util.Vector extraHeaders)
             throws java.io.IOException

Sends a mail message with some custom-specified envelope headers. Used internally by the other Qsmtp sendmsg and sendHTMLmsg methods.

Parameters:
from_address - Who is sending this message?
to_addresses - Vector of string addresses to send this message to
subject - Subject for this message
message - The text for the mail message
extraHeaders - Vector of string headers to include in the message's envelope
Throws:
java.io.IOException

run

public void run()

Main worker routine for the background thread which handles mail-outs.

Specified by:
run in interface java.lang.Runnable

dispatchMessage

private void dispatchMessage(Qsmtp.messageObject msgObj)
                      throws java.io.IOException

This method handles the actual mail-out

Throws:
java.io.IOException

formatDate

public static java.lang.String formatDate(java.util.Date date)

This method returns a properly mail-formatted date string.