SilverStream
Application Server 3.5

com.sssw.srv.mail
Class AgoMailSend

java.lang.Object
 |
 +--com.sssw.srv.mail.AgoMailSend

public class AgoMailSend
extends Object

Provides easy-to-use methods to construct and send RFC 822/MIME-compliant e-mail messages from the SilverStream Server.


Constructor Summary
AgoMailSend()
          The constructor for the AgoMailSend class.
 
Method Summary
 void addBccAddress(String name, String address)
          Adds a Bcc: (blind carbon copy) address to the message being constructed.
 void addCcAddress(String name, String address)
          Adds a Cc: (carbon copy) address to the message being constructed.
 void addCcAddress(String name, String address, String charset)
          Adds a Cc: (carbon copy) address to the message being constructed.
 void addFileAttachment(String filename)
          Adds a file attachment to the message.
 void addHTMLTextPart(Reader reader)
          Adds an HTML text part from a Reader.
 void addHTMLTextPart(Reader reader, String charset, String encoding)
          Adds an HTML text part from a Reader.
 void addHTMLTextPart(String text)
          Adds an HTML text part from a String.
 void addHTMLTextPart(String text, String charset, String encoding)
          Adds an HTML text part from a String buffer.
 void addHTMLTextPartFromFile(String filename)
          Adds an HTML text part from a file.
 void addHTMLTextPartFromFile(String filename, String charset, String encoding)
          Adds an HTML text part from a file.
 void addPart(AgoMIMEPart part)
          Add a part to this message.
 void addPlainTextPart(Reader reader)
          Adds a plain text part from a Reader.
 void addPlainTextPart(Reader reader, String charset, String encoding)
          Adds a plain text part from a Reader.
 void addPlainTextPart(String text)
          Adds a plain text part from a String buffer.
 void addPlainTextPart(String text, String charset, String encoding)
          Adds a plain text part from a String buffer.
 void addPlainTextPartFromFile(String filename)
          Adds a plain text part from a file.
 void addPlainTextPartFromFile(String filename, String charset, String encoding)
          Adds a plain text part from a file.
 void addToAddress(String name, String address)
          Adds a To: (primary) address to the message being constructed.
 void addToAddress(String name, String address, String charset)
          Adds a To: (primary) address to the message being constructed.
 void removeBccAddresses()
          Removes all the Bcc: addresses from the message.
 void removeCcAddresses()
          Removes all the Cc: addresses from the message.
 void removeToAddresses()
          Removes all the To: addresses from the message.
 void setFrom(String name, String address)
          Sets the From: address that appears on the message.
 void setFrom(String name, String address, String charset)
          Sets the From: address that appears on the message.
 void setOrganization(String organization)
          Sets the name of the organization that appears on the message.
 void setOrganization(String organization, String charset)
          Sets the name of the organization that appears on the message.
 void setReplyTo(String name, String address)
          Sets the Reply to: address that appears on the message.
 void setReplyTo(String name, String address, String charset)
          Sets the Reply to: address that appears on the message.
 void setSubject(String subject)
          Sets the Subject that appears on the message.
 void setSubject(String subject, String charset)
          Sets the Subject that appears on the message.
 String submitMessage(String server)
          Submits the message to the specified SMTP server.
 String submitMessage(String server, String domain)
          Submit the message to the specified from the specified domain.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgoMailSend

public AgoMailSend()
The constructor for the AgoMailSend class.
Example:

The following code fragment illustrates how to create a new message by instantiating the AgoMailSend class.

     AgoMailSend msg = new AgoMailSend();
     msg.setFrom("Bob Jones", "jones@company.com");
     msg.addToAddress("Chris Smith", "smith@company.com");
     msg.setSubject("Hi There");
     msg.setOrganization("XYZ Corp");
     msg.addPlainTextPart("Hello World!");
     msg.submitMessage("mail.company.com");
 
Method Detail

setFrom

public void setFrom(String name,
                    String address)
             throws AgoMailSendException
Sets the From: address that appears on the message.
Parameters:
name - a name to be associated with the From: address (e.g. Chris Smith). Optional.
address - the From: address (e.g. smith@company.com).
Usage:

The setFrom() method overwrites the current From address.

Example:

The following code fragment illustrates how to set the From address of a message.

      msg.setFrom("Chris Smith", "smith@company.com");
 

setFrom

public void setFrom(String name,
                    String address,
                    String charset)
             throws AgoMailSendException
Sets the From: address that appears on the message.
Parameters:
name - a name to be associated with the From: address (e.g. Chris Smith). Optional.
address - the From: address (e.g. smith@company.com).
charset - the character set of the Name.
Usage:

The setFrom() method overwrites the current From address.


setOrganization

public void setOrganization(String organization)
                     throws AgoMailSendException
Sets the name of the organization that appears on the message.
Parameters:
organization - the name of the organization.
Usage:

The setOrganization() method overwrites the current Organization.

Example:
     msg.setOrganization("XYZ Corp");
 

setOrganization

public void setOrganization(String organization,
                            String charset)
                     throws AgoMailSendException
Sets the name of the organization that appears on the message.
Parameters:
organization - the name of the organization.
charset - the character set of the Name.
Usage:

The setOrganization() method overwrites the current Organization.

Example:
     msg.setOrganization("XYZ Corp");
 

setReplyTo

public void setReplyTo(String name,
                       String address)
                throws AgoMailSendException
Sets the Reply to: address that appears on the message.
Parameters:
name - a name to be associated with the Reply to: address. (e.g. Chris Smith). Optional.
address - the Reply to: address. (e.g. smith@company.com).
Usage:

The setReplyTo() method overwrites the current Reply To address. If a message does not have a reply to address most mail programs will use the From field as described in RFC 822. As such, in common usage a reply to field is often unnecessary.

Example:

The following code fragment illustrates how to set a Reply To address.

      msg.setReplyTo("Chris Smith", "smith@company.com");
 

setReplyTo

public void setReplyTo(String name,
                       String address,
                       String charset)
                throws AgoMailSendException
Sets the Reply to: address that appears on the message.
Parameters:
name - a name to be associated with the Reply to: address. (e.g. Chris Smith). Optional.
address - the Reply to: address. (e.g. smith@company.com).
charset - the character set of the Name.
Usage:

The setReplyTo() method overwrites the current Reply To address. If a message does not have a reply to address most mail programs will use the From field as described in RFC 822. As such, in common usage a reply to field is often unnecessary.


setSubject

public void setSubject(String subject)
Sets the Subject that appears on the message.
Parameters:
subject - the message subject.
Usage:

The setSubject() method overwrites the current Subject.

Example:

The following code fragment illustrates how to set the Subject of a message.

      msg.setSubject("Meeting minutes");
 

setSubject

public void setSubject(String subject,
                       String charset)
Sets the Subject that appears on the message.
Parameters:
subject - the message subject.
charset - the character set of the Name.
Usage:

The setSubject() method overwrites the current Subject.


addToAddress

public void addToAddress(String name,
                         String address)
                  throws AgoMailSendException
Adds a To: (primary) address to the message being constructed.
Parameters:
name - a name to be associated with the To: address. (e.g. Chris Smith). Optional.
address - the To: address (e.g. smith@company.com).
Example:

The following code fragment illustrates how to add a To: address to a message.

     msg.addToAddress("Chris Smith", "smith@company.com");
 

addToAddress

public void addToAddress(String name,
                         String address,
                         String charset)
                  throws AgoMailSendException
Adds a To: (primary) address to the message being constructed.
Parameters:
name - a name to be associated with the To: address. (e.g. Chris Smith). Optional.
address - the To: address (e.g. smith@company.com).
charset - the character set for the name.

addCcAddress

public void addCcAddress(String name,
                         String address)
                  throws AgoMailSendException
Adds a Cc: (carbon copy) address to the message being constructed.
Parameters:
name - a name to be associated with the Cc: address. (e.g. Chris Smith). Optional.
address - the Cc: address (e.g. smith@company.com).
Example:

The following code fragment illustrates how to add a Cc address to a message.

      msg.addCcAddress("Chris Smith","smith@company.com");
 

addCcAddress

public void addCcAddress(String name,
                         String address,
                         String charset)
                  throws AgoMailSendException
Adds a Cc: (carbon copy) address to the message being constructed.
Parameters:
name - a name to be associated with the Cc: address. (e.g. Chris Smith). Optional.
address - the Cc: address (e.g. smith@company.com).
charset - the character set for the name.

addBccAddress

public void addBccAddress(String name,
                          String address)
                   throws AgoMailSendException
Adds a Bcc: (blind carbon copy) address to the message being constructed.
Parameters:
name - a name to be associated with the Bcc: address. (e.g. Chris Smith). Optional.
address - the Bcc: address (e.g. smith@company.com).
Example:

The following code fragment illustrates how to add a Bcc address to a message.

      msg.addBccAddress("Chris Smith", "smith@company.com");
 

removeToAddresses

public void removeToAddresses()
Removes all the To: addresses from the message.
Example:
     msg.removeToAddresses();
 

removeCcAddresses

public void removeCcAddresses()
Removes all the Cc: addresses from the message.
Example:
     msg.removeCcAddresses();
 

removeBccAddresses

public void removeBccAddresses()
Removes all the Bcc: addresses from the message.
Example:
     msg.removeBccAddresses();
 

addPlainTextPart

public void addPlainTextPart(String text)
                      throws AgoMailSendException
Adds a plain text part from a String buffer.
Parameters:
text - a String buffer that contains the text for the part.
Usage:

This version of the addPlainTextPart() method assumes the text is 7- bit US-ASCII. If the text is not 7-bit US-ASCII, use the three argument version of this method and specify the character set and desired encoding mechanism.

Example:

The following code fragment illustrates how to add a plain text part to a message.

         msg.addPlainTextPart("Hello World!");
 

addPlainTextPart

public void addPlainTextPart(String text,
                             String charset,
                             String encoding)
                      throws AgoMailSendException
Adds a plain text part from a String buffer.
Parameters:
text - a String buffer that contains the text for the part.
charset - the character set of the text (e.g. iso-8859-1). See AgoMIME for a list of supported character sets.
encoding - the encoding mechanism to use (e.g. quoted-printable). See AgoMIME for a list of supported encoding mechanisms.
Usage:

Note that the addPlainTextPart() method is overloaded. Use this version to specify the character set and desired encoding mechanism.


addPlainTextPart

public void addPlainTextPart(Reader reader)
                      throws AgoMailSendException
Adds a plain text part from a Reader.
Parameters:
reader - the Reader that contains the text for the part.
Usage:

This version of the addPlainTextPart() method assumes the text is 7- bit US-ASCII. If the text is not 7-bit US-ASCII, use the three argument version of this method and specify the character set and desired encoding mechanism.

Example:
     FileReader r = new FileReader(defaultFileReader);
     msg.addPlainTextPart(r);
 

addPlainTextPart

public void addPlainTextPart(Reader reader,
                             String charset,
                             String encoding)
                      throws AgoMailSendException
Adds a plain text part from a Reader.
Parameters:
reader - the Reader that contains the text for the part.
charset - the character set of the text (e.g. iso-8859-1). See AgoMIME for a list of supported character sets.
encoding - the encoding mechanism to use (e.g. quoted-printable). See AgoMIME for a list of supported encoding mechanisms.
Usage:

Note that the addPlainTextPart() method is overloaded. Use this version to add a plain text part from a Reader and specify the character set and desired encoding mechanism for the text.


addPlainTextPartFromFile

public void addPlainTextPartFromFile(String filename)
                              throws AgoMailSendException
Adds a plain text part from a file.
Parameters:
filename - the name of the file that contains the text for the part.
Usage:

This version of the addPlainTextPartFromFile() method assumes the text is 7- bit US-ASCII. If the text is not 7-bit US-ASCII, use the three argument version of this method and specify the character set and desired encoding mechanism.

Example:
     msg.addPlainTextPartFromFile("c:\\someDirectory\\someFile.txt");
 

addPlainTextPartFromFile

public void addPlainTextPartFromFile(String filename,
                                     String charset,
                                     String encoding)
                              throws AgoMailSendException
Adds a plain text part from a file.
Parameters:
filename - the name of the file that contains the text for the part.
charset - the character set of the text (e.g. iso-8859-1). See AgoMIME for a list of supported character sets.
encoding - the encoding mechanism to use (e.g. quoted-printable). See AgoMIME for a list of supported encoding mechanisms.
Usage:

Note that the addPlainTextPartFromFile() method is overloaded. Use this version to specify the character set and desired encoding mechanism.


addHTMLTextPart

public void addHTMLTextPart(String text)
                     throws AgoMailSendException
Adds an HTML text part from a String.
Parameters:
text - the name of the file that contains the HTML text for the part.
Usage:

This version of the addHTMLTextPart() method assumes the text is 7- bit US-ASCII. If the text is not 7-bit US-ASCII, use the three argument version of this method and specify the character set and desired encoding mechanism.

Example:

The following code fragment illustrates how to add an HTML text part to a message.

       msg.addHTMLTextPart("<HTML><P>Hello World!</HTML>");

addHTMLTextPart

public void addHTMLTextPart(String text,
                            String charset,
                            String encoding)
                     throws AgoMailSendException
Adds an HTML text part from a String buffer.
Parameters:
text - a String buffer that contains the HTML text for the part.
charset - the character set of the text (e.g. iso-8859-1). See AgoMIME for a list of supported character sets.
encoding - the encoding mechanism to use (e.g. quoted-printable). See AgoMIME for a list of supported encoding mechanisms.
Usage:

Note that the addHTMLTextPart() method is overloaded. Use this version to specify the character set and the encoding mechanism.

Example:

The following code fragment illustrates how to add an HTML text part:

        msg.addHTMLTextPart("<HTML><P>Hello World!</HTML>",
                            AgoMIME.CHARSET_ISO_8859_1,
                            AgoMIME.MECHANISM_QUOTED_PRINTABLE);
 

addHTMLTextPart

public void addHTMLTextPart(Reader reader)
                     throws AgoMailSendException
Adds an HTML text part from a Reader.
Parameters:
reader - a Reader that contains the HTML text for the part.
Usage:

This version of the addHTMLTextPart() method assumes the text is 7- bit US-ASCII. If the text is not 7-bit US-ASCII, use the three argument version of this method and specify the character set and desired encoding mechanism.

Example:

The following code fragment illustrates how to add an HTML text part:

 	FileReader r=new FileReader(defaultReaderFile);
 	msg.addHTMLTextPart(r);
 

addHTMLTextPart

public void addHTMLTextPart(Reader reader,
                            String charset,
                            String encoding)
                     throws AgoMailSendException
Adds an HTML text part from a Reader.
Parameters:
reader - a Reader that contains the HTML text for the part.
charset - the character set of the text (e.g. iso-8859-1). See AgoMIME for a list of supported character sets.
encoding - the encoding mechanism to use (e.g. quoted-printable). See AgoMIME for a list of supported encoding mechanisms.
Usage:

Note that the addHTMLTextPart() method is overloaded. Use this version to add an HTML text part from a Reader and specify the character set and desired encoding mechanism.


addHTMLTextPartFromFile

public void addHTMLTextPartFromFile(String filename)
                             throws AgoMailSendException
Adds an HTML text part from a file.
Parameters:
filename - the name of the file that contains the HTML text for the part.
Usage:

This version of the addHTMLTextPartFromFile() method assumes the text is 7- bit US-ASCII. If the text is not 7-bit US-ASCII, use the three argument version of this method and specify the character set and desired encoding mechanism.

Example:
     	msg.addHTMLTextPartFromFile("someFile.txt");
 

addHTMLTextPartFromFile

public void addHTMLTextPartFromFile(String filename,
                                    String charset,
                                    String encoding)
                             throws AgoMailSendException
Adds an HTML text part from a file.
Parameters:
filename - the name of the file that contains the HTML text for the part.
charset - the character set of the text (e.g. iso-8859-1). See AgoMIME for a list of supported character sets.
encoding - the encoding mechanism to use (e.g. quoted-printable). See AgoMIME for a list of supported encoding mechanisms.
Usage:

Note that the addHTMLTextPartFromFile() method is overloaded. Use this version to specify the character set and desired encoding mechanism.


addFileAttachment

public void addFileAttachment(String filename)
                       throws AgoMailSendException
Adds a file attachment to the message.
Parameters:
filename - the name of the file to be attached.
Usage:

A file attachment is always added as a new MIME part of Content-Type application/octet-stream. If there is more than one part, the message automatically becomes a multipart message.

Example:

The following code fragment illustrates how to add a file attachment to a message.

      msg.addFileAttachment("temp\foo.exe");
 
See Also:
AgoMailSend.addPlainTextPartFromFile(java.lang.String)

submitMessage

public String submitMessage(String server)
                     throws AgoMailSendException
Submits the message to the specified SMTP server. It returns the generated Message ID of the sent message.
Parameters:
server - the name of the server.
Returns:
Message id of submitted message.
Example:

The following code fragment shows how to submit a message to the mail.company.com SMTP server.

      msg.submitMessage("mail.company.com");
 

submitMessage

public String submitMessage(String server,
                            String domain)
                     throws AgoMailSendException
Submit the message to the specified from the specified domain.
Parameters:
server - The name of the SMTP server to use to send the mail
domain - The domain name of the server (e.g. silverstream.com)
Returns:
Message id of submitted message.
Usage:

Some mailers check the domain of the sender. Note that this check does not provide genuine security.


addPart

public void addPart(AgoMIMEPart part)
Add a part to this message.
Parameters:
part - the new part for this message.
Usage:

If the part you add is the first part, it becomes the message part. If another part is added, this will become the first part of a multipart message.

Note that adding a part does not add headers to a message. Headers (To, Subject, CC, etc.) must be added using the other methods in this class.

See Also:
AgoMailSend.setFrom( String name, String address ), AgoMailSend.setOrganization( String organization ), AgoMailSend.setReplyTo( String name, String address ), AgoMailSend.setSubject( String subject ), AgoMailSend.addToAddress( String name, String address ), AgoMailSend.addCcAddress( String name, String address )

SilverStream
Application Server 3.5