com.jalios.jcms
Class MailMessage

java.lang.Object
  extended by com.jalios.jcms.MailMessage

public class MailMessage
extends Object

Class used to build and send a mail message.

Example :

   MailMessage msg = new MailMessage("myplugin.log-mail");
   msg.setTo(channel.getDefaultAdmin())
      .setSubject("[" + channel.getName() + "] Daily log")
      .setContentText("Daily log attached")
      .addFile(new File(channel.getRealPath("WEB-INF/data/logs/jcms.log")))
      .send();
   logger.info("Log mail sent in " + Util.formatDuration(msg.getDuration()));
 
   MailMessage msg = new MailMessage("starwarsplugin.war-mail-alert");
   msg.setFrom("Darth Vader <dv@deathstar.com>");
   msg.setTo("Son <luke@alliance.com>");
   msg.setBcc("Palpatine <palpatine@deathstar.com>");
   for (Member sithMbr : sithGroup.getMemberSet()) {   
      msg.addCc(sithMbr);
   }
   msg.setSubject("I am your father");
   msg.setContentText("The Force is with you, young Skywalker. But you are not a Jedi yet.");
   msg.setContentHtml("The <strong>Force</strong> is with you, young Skywalker. But you are not a Jedi yet.");
   msg.send();
 

Since:
jcms-6.0.1
Version:
$Revision: 23252 $

Field Summary
protected  long duration
           
static String REVISION
           
 
Constructor Summary
MailMessage(String origin)
          Builds a new empty MailMessage.
 
Method Summary
 MailMessage addBcc(Member bccMbr)
          Add the specified Member as a "Bcc:" recipient of this MailMessage.
 MailMessage addBcc(String bccEmails)
          Add the specified emails as "Bcc:" recipient of this MailMessage.
 MailMessage addCc(Member ccMbr)
          Add the specified Member as a "Cc:" recipient of this MailMessage.
 MailMessage addCc(String ccEmails)
          Add the specified emails as "Cc:" recipient of this MailMessage.
 MailMessage addFile(File file)
          Add a file to send with this MailMessage.
 MailMessage addFile(File file, String id)
          Add a file to send with this MailMessage.
 MailMessage addReplyTo(Member replyToMbr)
          Add the specified Member as a "ReplyTo:" of this MailMessage.
 MailMessage addReplyTo(String replyToEmails)
          Add the specified emails as "ReplyTo:" of this MailMessage.
 MailMessage addTo(Member toMbr)
          Add the specified Member as a "To:" recipient of this MailMessage.
 MailMessage addTo(String toEmails)
          Add the specified emails as "To:" recipient of this MailMessage.
 Set<Member> getBccMemberSet()
          Retrieve the Set of Member that will receive blind copy of this MailMessage.
 Set<String> getBccSet()
          Retrieve the Set of email addresses recipient blind copies of this MailMessage.
 Set<Member> getCcMemberSet()
          Retrieve the Set of Member that will receive copy of this MailMessage.
 Set<String> getCcSet()
          Retrieve the Set of email addresses recipient copies of this MailMessage.
 String getContentHtml()
          Retrieve the HTML text content of this MailMessage.
 String getContentText()
          Retrieve the plain text content of this MailMessage.
 long getDuration()
          Retrieve the time the sending process took to execute.
 Map<File,String> getFileMap()
          Retrieve the Map of File/id to send in this MailMessage.
 String getFrom()
          Retrieve the "From" email address of this MailMessage.
 Member getFromMember()
          Retrieve the Member sender of this MailMessage.
 String getOrigin()
          Retrieve an identifier indicating the origin of this MailMessage in JCMS.
 int getPriority()
          Retrieve the Priority of this MailMessage.
 Set<Member> getReplyToMemberSet()
          Retrieve the Set of Member for ReplyTo this MailMessage.
 Set<String> getReplyToSet()
          Retrieve the Set of email addresses for ReplyTo of this MailMessage.
 String getSubject()
          Retrieve the subject of this MailMessage.
 Set<Member> getToMemberSet()
          Retrieve the Set of Member recipient of this MailMessage.
 Set<String> getToSet()
          Retrieve the Set of email addresses recipient of this MailMessage.
 void send()
          Send this MailMessage.
 MailMessage setBcc(Member bccMbr)
          Set the Member that will receive blind copy of this MailMessage.
 MailMessage setBcc(String bccEmails)
          Set the email addresses that will receive blind copy of this MailMessage.
 MailMessage setCc(Member ccMbr)
          Set the Member that will receive copy of this MailMessage.
 MailMessage setCc(String ccEmails)
          Set the email addresses that will receive copy of this MailMessage.
 MailMessage setContentHtml(String textHtml)
          Set the HTML text content of this MailMessage.
 MailMessage setContentHtmlFromJsp(String jspPath, Member loggedMember, String language, HashMap<Object,Object> requestAttribute, HashMap<Object,Object> sessionAttribute)
          Set the HTML text content of this MailMessage from the rendering of the specified jsp.
 MailMessage setContentText(String textPlain)
          Set the plain text content of this MailMessage.
 MailMessage setContentTextFromJsp(String jspPath, Member loggedMember, String language, HashMap<Object,Object> requestAttribute, HashMap<Object,Object> sessionAttribute)
          Set the plain text content of this MailMessage from the rendering of the specified jsp.
 MailMessage setFrom(Member member)
          Set the Member sending this MailMessage.
 MailMessage setFrom(String from)
          Set the email address sender of this MailMessage.
 MailMessage setPriority(int priority)
          Set the priority of this MailMessage.
 MailMessage setReplyTo(Member replyToMbr)
          Set the Member ReplyTo of this MailMessage.
 MailMessage setReplyTo(String replyToEmails)
          Set the email addresses ReplyTo of this MailMessage.
 MailMessage setSubject(String subject)
          Set the subject of this MailMessage.
 MailMessage setTo(Member toMbr)
          Set the Member recipient of this MailMessage.
 MailMessage setTo(String toEmails)
          Set the email addresses recipient of this MailMessage.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

duration

protected long duration
Constructor Detail

MailMessage

public MailMessage(String origin)
Builds a new empty MailMessage.

Parameters:
origin - an identifier indicating the feature/origin of this MailMessage e.g "newsletter", "myplugin.mail-alert"
Method Detail

getOrigin

public String getOrigin()
Retrieve an identifier indicating the origin of this MailMessage in JCMS.

Returns:
an identifier e.g "newsletter"

getFrom

public String getFrom()
Retrieve the "From" email address of this MailMessage.

Default value is the mail returned by Channel.getSenderFullEmail()

Returns:
a mail address, e.g "Foo Bar" <foobar@company.com>

getFromMember

public Member getFromMember()
Retrieve the Member sender of this MailMessage.

The member only be available if it was set using method setFrom(Member)

Returns:
a mail address, e.g "Foo Bar" <foobar@company.com>

setFrom

public MailMessage setFrom(String from)
Set the email address sender of this MailMessage.

Replace any value set using setFrom(Member)

Parameters:
from - a mail address, e.g "Foo Bar" <foobar@company.com>
Returns:
this (for method chaining)

setFrom

public MailMessage setFrom(Member member)
Set the Member sending this MailMessage.

Replace any value set using setFrom(String)

Parameters:
member - a mail address, e.g "Foo Bar" <foobar@company.com>
Returns:
this (for method chaining)

getToSet

public Set<String> getToSet()
Retrieve the Set of email addresses recipient of this MailMessage.

This set will only be filled if recipients were added using method setTo(String)

getToSet() and getToMemberSet() do not contains the same information and may be used simultaneously

Returns:
a Set of mail addresses

getToMemberSet

public Set<Member> getToMemberSet()
Retrieve the Set of Member recipient of this MailMessage.

This set will only be filled if recipients of this MailMessage were specified using method setTo(Member)}

getToSet() and getToMemberSet() do not contains the same information and may be used simultaneously

Returns:
a Set of Member

setTo

public MailMessage setTo(String toEmails)
Set the email addresses recipient of this MailMessage.

Replace any value set using setTo(Member)}

Parameters:
toEmails - a string containing one or several mail addresses seperated with comma, e.g "Foo Bar" <foobar@company.com>, "John Smith" <js@company.com>
Returns:
this (for method chaining)

setTo

public MailMessage setTo(Member toMbr)
Set the Member recipient of this MailMessage.

Replace any value set using setTo(String)}

Parameters:
toMbr - the Member recipient of this mail
Returns:
this (for method chaining)

addTo

public MailMessage addTo(String toEmails)
Add the specified emails as "To:" recipient of this MailMessage.

Parameters:
toEmails - a string containing one or several mail addresses seperated with comma, e.g "Foo Bar" <foobar@company.com>, "John Smith" <js@company.com>
Returns:
this (for method chaining)

addTo

public MailMessage addTo(Member toMbr)
Add the specified Member as a "To:" recipient of this MailMessage.

Parameters:
toMbr - the Member to add as a "To:" recipient of this mail
Returns:
this (for method chaining)

getCcSet

public Set<String> getCcSet()
Retrieve the Set of email addresses recipient copies of this MailMessage.

This set will only be filled if recipients copies were added using method setCc(String)

getCcSet() and getCcMemberSet() do not contains the same information and may be used simultaneously

Returns:
a Set of mail addresses

getCcMemberSet

public Set<Member> getCcMemberSet()
Retrieve the Set of Member that will receive copy of this MailMessage.

This set will only be filled if Member copies of this MailMessage were specified using method setCc(Member)}

getCcSet() and getCcMemberSet() do not contains the same information and may be used simultaneously

Returns:
a Set of Member

setCc

public MailMessage setCc(String ccEmails)
Set the email addresses that will receive copy of this MailMessage.

Replace any value set using setCc(Member)}

Parameters:
ccEmails - a string containing one or several mail addresses seperated with comma, e.g "Foo Bar" <foobar@company.com>, "John Smith" <js@company.com>
Returns:
this (for method chaining)

setCc

public MailMessage setCc(Member ccMbr)
Set the Member that will receive copy of this MailMessage.

Replace any value set using setCc(String)}

Parameters:
ccMbr - the Member recipient of a copy of this mail
Returns:
this (for method chaining)

addCc

public MailMessage addCc(String ccEmails)
Add the specified emails as "Cc:" recipient of this MailMessage.

Parameters:
ccEmails - a string containing one or several mail addresses seperated with comma, e.g "Foo Bar" <foobar@company.com>, "John Smith" <js@company.com>
Returns:
this (for method chaining)

addCc

public MailMessage addCc(Member ccMbr)
Add the specified Member as a "Cc:" recipient of this MailMessage.

Parameters:
ccMbr - the Member to add as a "Cc:" recipient of this mail
Returns:
this (for method chaining)

getBccSet

public Set<String> getBccSet()
Retrieve the Set of email addresses recipient blind copies of this MailMessage.

This set will only be filled if recipients blind copies were added using method setCc(String)

getBccSet() and getBccMemberSet() do not contains the same information and may be used simultaneously

Returns:
a Set of mail addresses

getBccMemberSet

public Set<Member> getBccMemberSet()
Retrieve the Set of Member that will receive blind copy of this MailMessage.

This set will only be filled if Member blindcopies of this MailMessage were specified using method setBcc(Member)}

getBccSet() and getBccMemberSet() do not contains the same information and may be used simultaneously

Returns:
a Set of Member

setBcc

public MailMessage setBcc(String bccEmails)
Set the email addresses that will receive blind copy of this MailMessage.

Replace any value set using setBcc(Member)}

Parameters:
bccEmails - a string containing one or several mail addresses seperated with comma, e.g "Foo Bar" <foobar@company.com>, "John Smith" <js@company.com>
Returns:
this (for method chaining)

setBcc

public MailMessage setBcc(Member bccMbr)
Set the Member that will receive blind copy of this MailMessage.

Replace any value set using setBcc(String)}

Parameters:
bccMbr - the Member recipient of a blind copy of this mail
Returns:
this (for method chaining)

addBcc

public MailMessage addBcc(String bccEmails)
Add the specified emails as "Bcc:" recipient of this MailMessage.

Parameters:
bccEmails - a string containing one or several mail addresses seperated with comma, e.g "Foo Bar" <foobar@company.com>, "John Smith" <js@company.com>
Returns:
this (for method chaining)

addBcc

public MailMessage addBcc(Member bccMbr)
Add the specified Member as a "Bcc:" recipient of this MailMessage.

Parameters:
bccMbr - the Member to add as a "Bcc:" recipient of this mail
Returns:
this (for method chaining)

getReplyToSet

public Set<String> getReplyToSet()
Retrieve the Set of email addresses for ReplyTo of this MailMessage.

This set will only be filled if replyto were added using method setReplyTo(String)

Returns:
a Set of mail addresses

getReplyToMemberSet

public Set<Member> getReplyToMemberSet()
Retrieve the Set of Member for ReplyTo this MailMessage.

This set will only be filled if ReplyTo of this MailMessage were specified using method setReplyTo(Member)}

Returns:
a Set of Member

setReplyTo

public MailMessage setReplyTo(String replyToEmails)
Set the email addresses ReplyTo of this MailMessage.

Replace any value set using setTo(Member)}

Parameters:
replyToEmails - a string containing one or several mail addresses seperated with comma, e.g "Foo Bar" <foobar@company.com>, "John Smith" <js@company.com>
Returns:
this (for method chaining)

setReplyTo

public MailMessage setReplyTo(Member replyToMbr)
Set the Member ReplyTo of this MailMessage.

Replace any value set using setTo(String)}

Parameters:
replyToMbr - the Member ReplyTo of this mail
Returns:
this (for method chaining)

addReplyTo

public MailMessage addReplyTo(String replyToEmails)
Add the specified emails as "ReplyTo:" of this MailMessage.

Parameters:
replyToEmails - a string containing one or several mail addresses seperated with comma, e.g "Foo Bar" <foobar@company.com>, "John Smith" <js@company.com>
Returns:
this (for method chaining)

addReplyTo

public MailMessage addReplyTo(Member replyToMbr)
Add the specified Member as a "ReplyTo:" of this MailMessage.

Parameters:
replyToMbr - the Member to add as a "ReplyTo:" of this mail
Returns:
this (for method chaining)

getSubject

public String getSubject()
Retrieve the subject of this MailMessage.

Returns:
a string or null if was not defined.

setSubject

public MailMessage setSubject(String subject)
Set the subject of this MailMessage.

Parameters:
subject - the subject to use for this MailMessage
Returns:
this (for method chaining)

getContentText

public String getContentText()
Retrieve the plain text content of this MailMessage.

Returns:
a plain text string or null if was not defined.

setContentText

public MailMessage setContentText(String textPlain)
Set the plain text content of this MailMessage.

Parameters:
textPlain - the plain text content to use for this MailMessage
Returns:
this (for method chaining)

setContentTextFromJsp

public MailMessage setContentTextFromJsp(String jspPath,
                                         Member loggedMember,
                                         String language,
                                         HashMap<Object,Object> requestAttribute,
                                         HashMap<Object,Object> sessionAttribute)
Set the plain text content of this MailMessage from the rendering of the specified jsp.

Parameters:
jspPath - a jsp path relative to the webapp root e.g "/custom/jcms/doNotificationText.jsp"
loggedMember - the Member that will be set as the logged member when invoking jsp
language - the language that will be set when invoking jsp
requestAttribute - a HashMap of request attribute available to the jsp execution
sessionAttribute - a HashMap of session attribute available to the jsp execution
Returns:
this (for method chaining)

getContentHtml

public String getContentHtml()
Retrieve the HTML text content of this MailMessage.

Returns:
a HTML text string or null if was not defined.

setContentHtml

public MailMessage setContentHtml(String textHtml)
Set the HTML text content of this MailMessage.

Parameters:
textHtml - the HTML text content to use for this MailMessage
Returns:
this (for method chaining)

setContentHtmlFromJsp

public MailMessage setContentHtmlFromJsp(String jspPath,
                                         Member loggedMember,
                                         String language,
                                         HashMap<Object,Object> requestAttribute,
                                         HashMap<Object,Object> sessionAttribute)
Set the HTML text content of this MailMessage from the rendering of the specified jsp.

Parameters:
jspPath - a jsp path relative to the webapp root e.g "/custom/jcms/doNotificationText.jsp"
loggedMember - the Member that will be set as the logged member when invoking jsp
language - the language that will be set when invoking jsp
requestAttribute - a HashMap of request attribute available to the jsp execution
sessionAttribute - a HashMap of session attribute available to the jsp execution
Returns:
this (for method chaining)

getPriority

public int getPriority()
Retrieve the Priority of this MailMessage.

Returns:
an integer between 1 and 5 included. 5 being the lowest, 3 being the "normal" and 1 the highest priority.

setPriority

public MailMessage setPriority(int priority)
Set the priority of this MailMessage.

Parameters:
priority - an integer between 1 and 5 included. 5 being the lowest, 3 being the "normal" and 1 the highest priority.
Returns:
this (for method chaining)

getFileMap

public Map<File,String> getFileMap()
Retrieve the Map of File/id to send in this MailMessage.

Returns:
a Map with File as the key and an optionnal id as the value (may return null if no file was added yet).

addFile

public MailMessage addFile(File file)
Add a file to send with this MailMessage.

Parameters:
file - a File to send.
Returns:
this (for method chaining)

addFile

public MailMessage addFile(File file,
                           String id)
Add a file to send with this MailMessage.

Parameters:
file - a File to send.
id - an optionnal identifier for this file
Returns:
this (for method chaining)

getDuration

public long getDuration()
Retrieve the time the sending process took to execute.

Returns:
a duration in millisecond (0 if sending did not occured yet)

send

public void send()
          throws javax.mail.MessagingException
Send this MailMessage.

Throws:
javax.mail.MessagingException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2001-2007 Jalios SA. All Rights Reserved.