pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.email
Class Email

java.lang.Object
  extended by org.torweg.pulse.email.Email
All Implemented Interfaces:
java.io.Serializable

public class Email
extends java.lang.Object
implements java.io.Serializable

is a class for constructing and sending emails. The class is capable of plain text mails, HTML mails, HTML mails with inline images, alternative content mails (text + HTML) and adding attachments to any of the former.

Version:
$Revision: 2025 $
Author:
Thomas Weber
See Also:
Serialized Form

Constructor Summary
Email()
          creates and configures a new Email.
Email(EmailConfiguration conf)
          creates a new Email from the given configuration without initialising the email body.
Email(EmailConfiguration conf, org.jdom.Document d)
          creates a new Email from the given configuration and the given XML document.
Email(EmailConfiguration conf, org.jdom.Element e)
          creates a new Email from the given configuration and the given XML element.
Email(EmailConfiguration conf, java.lang.Object jaxbAble)
          creates a new Email from the given configuration and the given JAXB enabled object.
 
Method Summary
 javax.mail.internet.MimeMessage asMimeMessage(javax.mail.Session session)
          returns the Email as a MimeMessage.
 void clearAttachments()
          clears the attachments.
 void clearInlineImages()
          clears the inline images.
protected  java.lang.String getReturnPath()
          returns the return-path address as a string.
protected  boolean isReturnPathSet()
          returns whether the e-mail has a return-path set.
 void putInlineImage(java.lang.String cid, SerializableDataSource att)
          sets the images referenced froms the HTML content.
 void setAttachment(java.io.File file)
          convenience method for setting a single file attachment.
 void setAttachment(SerializableDataSource att)
          convenience method for setting a single file attachment.
 void setAttachments(java.util.Collection<SerializableDataSource> atts)
          sets the attachments for the Email.
 void setAttachments(java.io.File[] files)
          sets the attachments for the Email.
 void setAttachments(java.util.Map<java.lang.String,java.io.File> filesMap)
          Sets the attachments from a map which maps file-names to Files.
 void setAttachments(java.util.Set<java.io.File> files)
          sets the attachments for the Email.
 void setFrom(java.util.Collection<javax.mail.internet.InternetAddress> f)
          sets the froms addresses of the Email.
 void setFrom(javax.mail.internet.InternetAddress f)
          sets the froms of the Email.
 void setFrom(java.lang.String realName, java.lang.String emailAddress)
          sets the froms of the Email.
 void setFrom(java.lang.String realName, java.lang.String emailAddress, java.lang.String encoding)
          sets the froms of the Email.
 void setHTMLContent(java.lang.String html)
          sets the text/html content of the Email.
 void setInlineImages(java.util.Map<java.lang.String,java.io.File> images)
          sets the images referenced froms the HTML content.
 void setRecipient(javax.mail.internet.InternetAddress r)
          sets the recipients of the Email.
 void setRecipient(java.lang.String realName, java.lang.String emailAddress)
          sets the recipients of the Email.
 void setRecipient(java.lang.String realName, java.lang.String emailAddress, java.lang.String encoding)
          sets the recipients of the Email.
 void setReplyTo(javax.mail.internet.InternetAddress r)
          sets the reply-to of the Email.
 void setReplyTo(java.lang.String realName, java.lang.String emailAddress)
          sets the reply-to of the Email.
 void setReplyTo(java.lang.String realName, java.lang.String emailAddress, java.lang.String encoding)
          sets the reply-to of the Email.
 void setReturnPath(java.lang.String emailAddress)
          sets the return path of the Email.
 void setSubject(java.lang.String s)
          sets the subject of the Email.
 void setTextContent(java.lang.String text)
          sets the text/plain content of the Email.
 java.lang.String toString()
          returns a string representation of the email giving the recipients and the subject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Email

public Email()
creates and configures a new Email.


Email

public Email(EmailConfiguration conf)
creates a new Email from the given configuration without initialising the email body.

Parameters:
conf - the configuration

Email

public Email(EmailConfiguration conf,
             org.jdom.Document d)
creates a new Email from the given configuration and the given XML document.

Parameters:
conf - the configuration
d - the document

Email

public Email(EmailConfiguration conf,
             org.jdom.Element e)
creates a new Email from the given configuration and the given XML element.

Parameters:
conf - the configuration
e - the element

Email

public Email(EmailConfiguration conf,
             java.lang.Object jaxbAble)
creates a new Email from the given configuration and the given JAXB enabled object. The global JAXB context will be used for marshaling.

Parameters:
conf - the configuration
jaxbAble - the JAXB enabled object
Method Detail

setSubject

public final void setSubject(java.lang.String s)
sets the subject of the Email.

Parameters:
s - the subject

setFrom

public final void setFrom(java.lang.String realName,
                          java.lang.String emailAddress,
                          java.lang.String encoding)
                   throws java.io.UnsupportedEncodingException
sets the froms of the Email.

Parameters:
realName - the froms's real name, for example John Doe
emailAddress - the froms's email address, for examle j.doe@something.org
encoding - the encoding to be used, for example ISO-8859-1 or utf-8
Throws:
java.io.UnsupportedEncodingException - if the requested encoding is not available

setFrom

public final void setFrom(java.lang.String realName,
                          java.lang.String emailAddress)
                   throws java.io.UnsupportedEncodingException
sets the froms of the Email.

Parameters:
realName - the froms's real name, for example John Doe
emailAddress - the froms's email address, for examle j.doe@something.org
Throws:
java.io.UnsupportedEncodingException - if the system is not able to provide utf-8 encoding

setFrom

public final void setFrom(javax.mail.internet.InternetAddress f)
sets the froms of the Email.

Parameters:
f - the froms address

setFrom

public final void setFrom(java.util.Collection<javax.mail.internet.InternetAddress> f)
sets the froms addresses of the Email.

Parameters:
f - the froms addresses

setReplyTo

public final void setReplyTo(java.lang.String realName,
                             java.lang.String emailAddress,
                             java.lang.String encoding)
                      throws java.io.UnsupportedEncodingException
sets the reply-to of the Email.

Parameters:
realName - the froms's real name, for example John Doe
emailAddress - the froms's email address, for examle j.doe@something.org
encoding - the encoding to be used, for example ISO-8859-1 or utf-8
Throws:
java.io.UnsupportedEncodingException - if the requested encoding is not available

setReplyTo

public final void setReplyTo(java.lang.String realName,
                             java.lang.String emailAddress)
                      throws java.io.UnsupportedEncodingException
sets the reply-to of the Email.

Parameters:
realName - the froms's real name, for example John Doe
emailAddress - the froms's email address, for examle j.doe@something.org
Throws:
java.io.UnsupportedEncodingException - if the system is not able to provide utf-8 encoding

setReplyTo

public final void setReplyTo(javax.mail.internet.InternetAddress r)
sets the reply-to of the Email.

Parameters:
r - the replay-to address

setReturnPath

public final void setReturnPath(java.lang.String emailAddress)
sets the return path of the Email.

Parameters:
emailAddress - the return path email address

getReturnPath

protected final java.lang.String getReturnPath()
returns the return-path address as a string.

Returns:
return-path

isReturnPathSet

protected final boolean isReturnPathSet()
returns whether the e-mail has a return-path set.

Returns:
true, if and only if the return-path is set. Otherwise false.

setRecipient

public final void setRecipient(javax.mail.internet.InternetAddress r)
sets the recipients of the Email.

Parameters:
r - the recipients

setRecipient

public final void setRecipient(java.lang.String realName,
                               java.lang.String emailAddress,
                               java.lang.String encoding)
                        throws java.io.UnsupportedEncodingException
sets the recipients of the Email.

Parameters:
realName - the recipients's real name, for example John Doe
emailAddress - the recipients's email address, for example j.doe@something.org
encoding - the encoding to be used, for example ISO-8859-1 or utf-8
Throws:
java.io.UnsupportedEncodingException - if the requested encoding is not available

setRecipient

public final void setRecipient(java.lang.String realName,
                               java.lang.String emailAddress)
                        throws java.io.UnsupportedEncodingException
sets the recipients of the Email.

Parameters:
realName - the recipients's real name, for example John Doe
emailAddress - the recipients's email address, for examle j.doe@something.org
Throws:
java.io.UnsupportedEncodingException - if the system is not able to provide utf-8 encoding

setTextContent

public final void setTextContent(java.lang.String text)
sets the text/plain content of the Email.

Parameters:
text - the text content

setHTMLContent

public final void setHTMLContent(java.lang.String html)
sets the text/html content of the Email.

Parameters:
html - the HTML content

setInlineImages

public final void setInlineImages(java.util.Map<java.lang.String,java.io.File> images)
sets the images referenced froms the HTML content.

Parameters:
images - a Hashtable with the images: the key is the content-id (cid) of the image, the value is a File pointing to the image's location

putInlineImage

public final void putInlineImage(java.lang.String cid, SerializableDataSource att)
sets the images referenced froms the HTML content.

Parameters:
cid - content-id (cid) of the image
att - a SerializableDataSource

clearInlineImages

public final void clearInlineImages()
clears the inline images.


setAttachment

public final void setAttachment(java.io.File file)
convenience method for setting a single file attachment.

Parameters:
file - the attachment

setAttachment

public final void setAttachment(SerializableDataSource att)
convenience method for setting a single file attachment.

Parameters:
att - the SerializableDataSource to set

setAttachments

public final void setAttachments(java.io.File[] files)
sets the attachments for the Email.

Parameters:
files - the files to be attached

setAttachments

public final void setAttachments(java.util.Set<java.io.File> files)
sets the attachments for the Email.

Parameters:
files - the files to be attached

setAttachments

public final void setAttachments(java.util.Collection<SerializableDataSource> atts)
sets the attachments for the Email.

Parameters:
atts - the attachments to set

setAttachments

public final void setAttachments(java.util.Map<java.lang.String,java.io.File> filesMap)
Sets the attachments from a map which maps file-names to Files.

Parameters:
filesMap - a map, mapping file names to Files

clearAttachments

public final void clearAttachments()
clears the attachments.


asMimeMessage

public final javax.mail.internet.MimeMessage asMimeMessage(javax.mail.Session session)
                                                    throws javax.mail.MessagingException
returns the Email as a MimeMessage.

Parameters:
session - the mail session
Returns:
the Email as a MimeMessage
Throws:
javax.mail.MessagingException - on errors creating the MimeMessage

toString

public final java.lang.String toString()
returns a string representation of the email giving the recipients and the subject.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the email