WebObjects 5.4.2

com.webobjects.appserver
Class WOMailDelivery

java.lang.Object
  extended by com.webobjects.appserver.WOMailDelivery

public class WOMailDelivery
extends Object

WOMailDelivery constructs and delivers email messages. It can send both plain-text messages (you supply the string) and rich-text messages (you supply the WOComponent).

WOMailDelivery requires a SMTP server to be set (if no value is provided, the default-and-probably-wrong "smtp" is used). You can set the SMTP server using a number of methods:

Usage: WOMailDelivery is a singleton, accessed via its sharedInstance() method:

 WOMailDelivery.sharedInstance().composePlainTextEmail(fromAddress, toAddresses, bccAddresses, subject, body, WOMailDelivery.SEND_NOW);
 

JavaMail vs. SmtpClient: WOMailDelivery will use JavaMail if it is installed, enabling features such as BCC addressing, MIME-encoded messages, threaded delivery and better SMTP server compatibility (otherwise the older sun.net.smtp.SmtpClient is used). You can install JavaMail by copying activation.jar and mail.jar (installed in /ThirdPartyJars) into /Library/WebObjects/Extensions.


Nested Class Summary
protected static class WOMailDelivery.ThreadedTransportSender
          Intentionally undocumented.
 
Field Summary
static boolean DONT_SEND
          Constant for passing as sendNow parameter to composeComponentEmail and composePlainTextEmail.
protected  Object mailSession
          Intentionally undocumented.
static boolean SEND_NOW
          Constant for passing as sendNow parameter to composeComponentEmail and composePlainTextEmail.
 
Constructor Summary
protected WOMailDelivery()
          This protected constructor initializes a newly-instantiated WOMailDelivery object.
 
Method Summary
 String composeComponentEmail(String aSender, NSArray toAddresses, NSArray bccAddresses, String aSubject, WOComponent aComponent, boolean sendNow)
          Composes and optionally delivers a rich-text email message.
 String composePlainTextEmail(String aSender, NSArray toAddresses, NSArray bccAddresses, String aSubject, String aMessage, boolean sendNow)
          Composes and optionally delivers a plain-text email message.
protected  boolean hasJavaMail()
          Intentionally undocumented.
protected  Object mailSession()
          Intentionally undocumented.
protected  String mimeMessageToString(Object smtpMessage)
          Intentionally undocumented.
protected  Object newMimeMessage(String fromEmailAddress, NSArray toEmailAddresses, NSArray bccEmailAddresses, String subject, String message, String contentType, boolean sendNow)
          Intentionally undocumented.
 void sendEmail(String mailString)
          Sends mailString, with mailString being a String conforming to the SMTP format.
static WOMailDelivery sharedInstance()
          Returns the shared instance of WOMailDelivery that all classes should use.
 String toString()
          Returns a String representation of the WOMailDelivery object containing the receiver's class name and the SMTP host name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mailSession

protected Object mailSession
Intentionally undocumented.

Since:
5.3

SEND_NOW

public static final boolean SEND_NOW
Constant for passing as sendNow parameter to composeComponentEmail and composePlainTextEmail.

See Also:
Constant Field Values

DONT_SEND

public static final boolean DONT_SEND
Constant for passing as sendNow parameter to composeComponentEmail and composePlainTextEmail.

See Also:
Constant Field Values
Constructor Detail

WOMailDelivery

protected WOMailDelivery()
This protected constructor initializes a newly-instantiated WOMailDelivery object. WebObjects applications shouldn't allocate WOMailDelivery objects, but instead should make use of the shared instance provided by WOMailDelivery's sharedInstance class method.

See Also:
WOMailDelivery.sharedInstance()
Method Detail

sharedInstance

public static WOMailDelivery sharedInstance()
Returns the shared instance of WOMailDelivery that all classes should use. Use this instead of creating another instance.

Returns:
the current application's WOMailDelivery singleton

composePlainTextEmail

public String composePlainTextEmail(String aSender,
                                    NSArray toAddresses,
                                    NSArray bccAddresses,
                                    String aSubject,
                                    String aMessage,
                                    boolean sendNow)
Composes and optionally delivers a plain-text email message.

Parameters:
aSender - Required String corresponding to the Sender of the mail
toAddresses - Required NSArray of addresses in the To list
bccAddresses - Optional NSArray of addresses in the Cc list. If JavaMail is not enabled, these addresses are added to toAddresses since sun.net.smtp.SmtpClient does not support BCC addressing.
aSubject - Required String corresponding to the Subject of the mail
aMessage - Required String message body using ASCII characters
sendNow - boolean flag indicating whether the mail is to be sent immediately
Returns:
the composed ASCII mail message as a String
Since:
5.3

composeComponentEmail

public String composeComponentEmail(String aSender,
                                    NSArray toAddresses,
                                    NSArray bccAddresses,
                                    String aSubject,
                                    WOComponent aComponent,
                                    boolean sendNow)
Composes and optionally delivers a rich-text email message.

The body of the message is the HTML generated when this method invokes generateResponse on aComponent. WOMailDelivery uses the WOCGIAdaptorURL default to complete all URLs in the message to be mailed, so the email's recipient can click on the URLs to visit them. If sendNow is true, the message is sent immediately.

Parameters:
aSender - Required String corresponding to the Sender of the mail
toAddresses - Required NSArray of addresses in the To list
bccAddresses - Optional NSArray of addresses in the Cc list. If JavaMail is not enabled, these addresses are added to toAddresses since sun.net.smtp.SmtpClient does not support BCC addressing.
aSubject - Required String corresponding to the Subject of the mail
aComponent - Required current component
sendNow - boolean flag indicating whether the mail is to be sent immediately
Returns:
the composed ASCII mail message as a String
Since:
5.3
See Also:
WOApplication.cgiAdaptorURL()

sendEmail

public void sendEmail(String mailString)
Sends mailString, with mailString being a String conforming to the SMTP format. The compose...Email methods return such Strings. Calling these methods with sendNow set to false allows the caller to modify the returned String before using this method to send it.

Parameters:
mailString - composed mail message as a String in SMTP format.
Since:
5.3

toString

public String toString()
Returns a String representation of the WOMailDelivery object containing the receiver's class name and the SMTP host name.

Overrides:
toString in class Object
Returns:
a String representation of the WOMailDelivery object

mailSession

protected Object mailSession()
Intentionally undocumented.

Since:
5.3

hasJavaMail

protected boolean hasJavaMail()
Intentionally undocumented.

Since:
5.3

newMimeMessage

protected Object newMimeMessage(String fromEmailAddress,
                                NSArray toEmailAddresses,
                                NSArray bccEmailAddresses,
                                String subject,
                                String message,
                                String contentType,
                                boolean sendNow)
Intentionally undocumented.

Since:
5.3

mimeMessageToString

protected String mimeMessageToString(Object smtpMessage)
Intentionally undocumented.

Since:
5.3

Last updated June 2008

Copyright © 2000-2008 Apple Inc.