com.opencms.defaults
Class CmsMail

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.opencms.defaults.CmsMail
All Implemented Interfaces:
I_CmsLogChannels, Runnable

public class CmsMail
extends Thread
implements I_CmsLogChannels

This class is used to send a mail using the JavaMail package. Sun's mail.jar and activation.jar are required, if this class should be used in any OpenCms class.

Sender and recipients addresses may be given as String or as CmsUser objects. Different constructors for setting additional CC and BCC addresses are provided.

Attachments can be added using the addAttachment() method. If the current HTTP request is a multipart/form-data request and contains uploaded files, all these files will be sent as attachments, too.

For performance reasons, this classes uses threads for sending mails. Mail threads can be initialized and started by :

Example:
String from = "waruschan.babachan@framfab.de";
String[] to = {"alexander.lucas@framfab.de"};
String subject = "Testmail";
String content = "Hello World!";
 
CmsMail mail=new CmsMail(cms, from, to, subject, content, "text/plain");
mail.start();

Since:
OpenCms 4.1.37. Previously, this class was part of the com.opencms.workplace package.
Version:
$Name: $ $Revision: 1.14 $ $Date: 2003/02/15 11:14:57 $
Author:
Waruschan Babachan , mla, Alexander Lucas

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface com.opencms.boot.I_CmsLogChannels
C_FLEX_CACHE, C_FLEX_LOADER, C_LOGGING, C_MODULE_CRITICAL, C_MODULE_DEBUG, C_MODULE_INFO, C_OPENCMS_CACHE, C_OPENCMS_CRITICAL, C_OPENCMS_CRONSCHEDULER, C_OPENCMS_DEBUG, C_OPENCMS_ELEMENTCACHE, C_OPENCMS_INFO, C_OPENCMS_INIT, C_OPENCMS_POOL, C_OPENCMS_STATICEXPORT, C_OPENCMS_STREAMING, C_PREPROCESSOR_IS_LOGGING
 
Constructor Summary
CmsMail(CmsObject cms, CmsUser from, CmsGroup to, String subject, String content, String type)
          Create a new email object with a CmsUser as sender and a CmsGroup as recipient(s).
CmsMail(CmsObject cms, CmsUser from, CmsUser[] to, String subject, String content, String type)
          Create a new email object with a CmsUser as sender and an array of CmsUser's as recipient(s).
CmsMail(CmsObject cms, String from, String[] to, String[] cc, boolean isBcc, String subject, String content, String type)
          Create a new email object with given FROM, TO and BCC addresses.
CmsMail(CmsObject cms, String from, String[] to, String[] cc, String[] bcc, String subject, String content, String type)
          Create a new email object with given FROM, TO, CC and BCC addresses.
CmsMail(CmsObject cms, String from, String[] to, String[] bcc, String subject, String content, String type)
          Create a new email object with given FROM, TO and BCC addresses.
CmsMail(CmsObject cms, String from, String[] to, String subject, String content, String type)
          Create a new email object with given FROM and TO addresses.
CmsMail(CmsUser from, CmsGroup to, String subject, String content, String type)
           
CmsMail(CmsUser from, CmsUser[] to, String subject, String content, String type)
           
CmsMail(String from, String[] to, String[] cc, String[] bcc, String subject, String content, String type)
           
CmsMail(String from, String[] to, String[] bcc, String subject, String content, String type)
           
CmsMail(String from, String[] to, String subject, String content, String type)
          The constuctors without CmsObject
 
Method Summary
 void addAttachment(String content, String type)
          Add a new attachment of the given content type to this CmsMail object.
protected  String getClassName()
          Helper method for printing nice classnames in error messages
 void run()
          Try sending the mail.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmsMail

public CmsMail(String from,
               String[] to,
               String subject,
               String content,
               String type)
        throws CmsException
The constuctors without CmsObject


CmsMail

public CmsMail(CmsUser from,
               CmsUser[] to,
               String subject,
               String content,
               String type)
        throws CmsException

CmsMail

public CmsMail(CmsUser from,
               CmsGroup to,
               String subject,
               String content,
               String type)
        throws CmsException

CmsMail

public CmsMail(String from,
               String[] to,
               String[] cc,
               String[] bcc,
               String subject,
               String content,
               String type)
        throws CmsException

CmsMail

public CmsMail(String from,
               String[] to,
               String[] bcc,
               String subject,
               String content,
               String type)
        throws CmsException

CmsMail

public CmsMail(CmsObject cms,
               CmsUser from,
               CmsUser[] to,
               String subject,
               String content,
               String type)
        throws CmsException
Create a new email object with a CmsUser as sender and an array of CmsUser's as recipient(s). Email addresses will be taken from the CmsUser properties.

Parameters:
cms - Cms object
from - User object that contains the address of sender.
to - User object that contains the address of recipient.
subject - Subject of email.
content - Content of email.
type - ContentType of email.

CmsMail

public CmsMail(CmsObject cms,
               CmsUser from,
               CmsGroup to,
               String subject,
               String content,
               String type)
        throws CmsException
Create a new email object with a CmsUser as sender and a CmsGroup as recipient(s). The sender's address will be taken from the CmsUser properties, the recipient's addresses from all CmsUsers belonging to the given group.

Parameters:
cms - Cms object.
from - User object that contains the address of sender.
to - Group object that contains the address of recipient.
subject - Subject of email.
content - Content of email.
type - ContentType of email.

CmsMail

public CmsMail(CmsObject cms,
               String from,
               String[] to,
               String[] cc,
               String[] bcc,
               String subject,
               String content,
               String type)
        throws CmsException
Create a new email object with given FROM, TO, CC and BCC addresses.

Parameters:
cms - Cms object.
from - Address of sender.
to - Address of recipient.
cc - Address of copy recipient.
bcc - Address of blank copy recipient.
subject - Subject of email.
content - Content of email.
type - ContentType of email.
See Also:
CmsMail(CmsObject,String, String[], String[], String, String, String)

CmsMail

public CmsMail(CmsObject cms,
               String from,
               String[] to,
               String[] bcc,
               String subject,
               String content,
               String type)
        throws CmsException
Create a new email object with given FROM, TO and BCC addresses.

Parameters:
cms - Cms object.
from - Address of sender.
to - Address of recipient.
bcc - Address of blank copy recipient.
subject - Subject of email.
content - Content of email.
type - ContentType of email.
See Also:
CmsMail(CmsObject,String, String[], String, String, String)

CmsMail

public CmsMail(CmsObject cms,
               String from,
               String[] to,
               String[] cc,
               boolean isBcc,
               String subject,
               String content,
               String type)
        throws CmsException
Create a new email object with given FROM, TO and BCC addresses.

Parameters:
cms - Cms object.
from - Address of sender.
to - Address of recipient.
cc - Address of copy recipient.
isBcc - dedined wheather the type of cc is a bcc or not.
subject - Subject of email.
content - Content of email.
type - ContentType of email.
See Also:
CmsMail(CmsObject,String, String[], String, String, String)

CmsMail

public CmsMail(CmsObject cms,
               String from,
               String[] to,
               String subject,
               String content,
               String type)
        throws CmsException
Create a new email object with given FROM and TO addresses.

Parameters:
cms - Cms object.
from - Address of sender.
to - Array with address(es) of recipient(s).
subject - Subject of email.
content - Content of email.
type - ContentType of email.
Method Detail

addAttachment

public void addAttachment(String content,
                          String type)
Add a new attachment of the given content type to this CmsMail object. The attachment will get a random name.

Parameters:
content - Content of the attachment.
type - Content type of the attachment.

getClassName

protected String getClassName()
Helper method for printing nice classnames in error messages

Returns:
class name in [ClassName] format

run

public void run()
Try sending the mail. This can take a few seconds to several minutes. We don't want the user to wait for the response of the current HTTP request. Therefore we are running this in a new thread. The user will get his response immediately, then.

Specified by:
run in interface Runnable
Overrides:
run in class Thread