com.quadrique.jbuildingblocks.core.io.email
Class JbbEmail

java.lang.Object
  extended by com.quadrique.jbuildingblocks.core.io.email.JbbEmail

public class JbbEmail
extends Object


Field Summary
static String CONTENT_TRANSFER_ENCODING_HEADER
          the "Content-Transfer-Encoding" header value as defined by RFC 2045 should be of the form: "Content-Transfer-Encoding : 8Bit"
static String CONTENT_TRANSFER_ENCODING_HEADER_VALUE
          the "Content-Transfer-Encoding" header value as defined by RFC 2045 should be of the form: "Content-Transfer-Encoding : 8Bit"
static String CONTENT_TYPE_IS_HTML_ISO_LATIN_1
          the "Content-Type" header value as defined by RFC 2045 should be of the form: Content-Type: text/html; charset="iso-8859-1"
static String CONTENT_TYPE_IS_PLAIN_TEXT_ISO_LATIN_1
          the "Content-Type" header value as defined by RFC 2045 should be of the form: Content-Type: text/plain; charset="iso-8859-1"
 
Method Summary
 void closePOP3Connection()
          This must be called once all interaction with the POP3 server and its messages has been completed.
 String convertEmailAddressListFromArrayListToString(ArrayList<String> liste)
           
 ArrayList<String> convertEmailAddressListFromStringToArrayList(String liste)
          To convert from a String which contains a semicolon separated list of email addresses to an ArrayList<String> instance which contains the individual email addresses (if any)
 ArrayList<String> getBcc()
           
 DataSource getBody()
           
 ArrayList<String> getCc()
           
 String getFrom()
           
 javax.mail.Session getSession()
           
 String getSubject()
           
 ArrayList<String> getTo()
           
 boolean isValidateEmailAddresses()
           
 void isValidEmailAddress(String emailAddress)
          To validate the syntax of an email address
 void isValidEmailAddressList(ArrayList<String> emailAddressList, boolean emptyAllowed)
          To validate the syntax of a list of email address
 void isValidEmailAddressList(String emailAddressList, boolean emptyAllowed)
          To validate the syntax of a list of email address
static JbbEmail newInstance()
          The one and only entry point to get this object
 void openPOP3Connection()
          Before doing anything with a POP3 server, call this method to establish the connection.
 ArrayList<javax.mail.Message> retrieveEmailFromPOP3Server(boolean leaveCopyOnServer)
          Retrieve email messages from a POP3 server
 void sendEmail()
           
 void sendEmailHtmlWithEmbeddedImages(HashMap<String,File> images)
          HTML email messages with image links (e.g.
 void sendEmailWithAttachments(ArrayList<File> files)
           
 void setBcc(ArrayList<String> bcc)
          To set the value of the 'bcc' field
 void setBcc(String bcc)
          To set the value of the 'bcc' field from a semicolon separated list of email addresses.
 void setBody(DataSource body)
          To set the body of the email
 void setBody(File body, String contentType)
          To set the body of the email from the content of a file.
 void setBody(String body, String contentType)
          To set the body of the email from the content of a String.
 void setBodyHtml(File body)
          To set the body of the email from the content of a file
The file content is assumed to be HTML.
 void setBodyHtml(String body)
          To set the body of the email from the content of a String
The String content is assumed to be HTML.
 void setBodyPlainText(File body)
          To set the body of the email from the content of a file
The file content is assumed to be plain text.
 void setBodyPlainText(String body)
          To set the body of the email from the content of a String
The String content is assumed to be plain text.
 void setCc(ArrayList<String> cc)
          To set the value of the 'cc' field
 void setCc(String cc)
          To set the value of the 'cc' field from a semicolon separated list of email addresses.
 void setFrom(String from)
           
 void setSession(JbbEmailSessionConfig config)
          To create a Session from the address of a smtp server
 void setSession(javax.mail.Session session)
           
 void setSubject(String subject)
           
 void setTo(ArrayList<String> to)
          To set the value of the 'to' field
 void setTo(String to)
          To set the value of the 'to' field from a semicolon separated list of email addresses.
 void setValidateEmailAddresses(boolean emailAddressValidation)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE_IS_PLAIN_TEXT_ISO_LATIN_1

public static final String CONTENT_TYPE_IS_PLAIN_TEXT_ISO_LATIN_1
the "Content-Type" header value as defined by RFC 2045 should be of the form: Content-Type: text/plain; charset="iso-8859-1"

See Also:
Constant Field Values

CONTENT_TYPE_IS_HTML_ISO_LATIN_1

public static final String CONTENT_TYPE_IS_HTML_ISO_LATIN_1
the "Content-Type" header value as defined by RFC 2045 should be of the form: Content-Type: text/html; charset="iso-8859-1"

See Also:
Constant Field Values

CONTENT_TRANSFER_ENCODING_HEADER

public static final String CONTENT_TRANSFER_ENCODING_HEADER
the "Content-Transfer-Encoding" header value as defined by RFC 2045 should be of the form: "Content-Transfer-Encoding : 8Bit"

See Also:
Constant Field Values

CONTENT_TRANSFER_ENCODING_HEADER_VALUE

public static final String CONTENT_TRANSFER_ENCODING_HEADER_VALUE
the "Content-Transfer-Encoding" header value as defined by RFC 2045 should be of the form: "Content-Transfer-Encoding : 8Bit"

See Also:
Constant Field Values
Method Detail

newInstance

public static JbbEmail newInstance()
The one and only entry point to get this object

Returns:
a new instance

setSession

public void setSession(JbbEmailSessionConfig config)
                throws Exception
To create a Session from the address of a smtp server

Parameters:
config - the address of a server and more
Throws:
Exception

setSession

public void setSession(javax.mail.Session session)
                throws Exception
Parameters:
session - The session to set.
Throws:
Exception

isValidEmailAddress

public void isValidEmailAddress(String emailAddress)
                         throws Exception
To validate the syntax of an email address

Parameters:
emailAddress - the email address to validate (e.g. "support@quadrique.com")
Throws:
Exception - if the email address is not valid

isValidEmailAddressList

public void isValidEmailAddressList(String emailAddressList,
                                    boolean emptyAllowed)
                             throws Exception
To validate the syntax of a list of email address

Parameters:
emailAddressList - a semicolon separated list of email addresses (e.g. "sales@quadrique.com;support@quadrique.com")
emptyAllowed - if false, an exception will be thrown if the list is empty
Throws:
Exception

isValidEmailAddressList

public void isValidEmailAddressList(ArrayList<String> emailAddressList,
                                    boolean emptyAllowed)
                             throws Exception
To validate the syntax of a list of email address

Parameters:
emailAddressList - a ArrayList<String> instance
emptyAllowed - if false, an exception will be thrown if the list is empty
Throws:
Exception

convertEmailAddressListFromStringToArrayList

public ArrayList<String> convertEmailAddressListFromStringToArrayList(String liste)
                                                               throws Exception
To convert from a String which contains a semicolon separated list of email addresses to an ArrayList<String> instance which contains the individual email addresses (if any)

Parameters:
liste - a semicolon separated list of email addresses (e.g. "sales@quadrique.com;support@quadrique.com")
Returns:
An ArrayList<String> instance which contains the individual email addresses (if any)
Throws:
Exception

setTo

public void setTo(ArrayList<String> to)
           throws Exception
To set the value of the 'to' field

Parameters:
to - a list of email address. Please note that only one email address is required and that multiple email addresses are supported.
Throws:
Exception

setTo

public void setTo(String to)
           throws Exception
To set the value of the 'to' field from a semicolon separated list of email addresses.

Parameters:
to - a semicolon separated list of email addresses (e.g. "support@quadrique.com" or "support@quadrique.com;sales@quadrique.com")
Please note that only one email address is required and that multiple email addresses are supported.
Throws:
Exception

setCc

public void setCc(ArrayList<String> cc)
           throws Exception
To set the value of the 'cc' field

Parameters:
cc - a list of email addresses.
Throws:
Exception

setCc

public void setCc(String cc)
           throws Exception
To set the value of the 'cc' field from a semicolon separated list of email addresses.

Parameters:
cc - a semicolon separated list of email addresses (e.g. "support@quadrique.com" or "support@quadrique.com;sales@quadrique.com")
Throws:
Exception

setBcc

public void setBcc(ArrayList<String> bcc)
            throws Exception
To set the value of the 'bcc' field

Parameters:
bcc - a list of email addresses.
Throws:
Exception

setBcc

public void setBcc(String bcc)
            throws Exception
To set the value of the 'bcc' field from a semicolon separated list of email addresses.

Parameters:
bcc - a semicolon separated list of email addresses (e.g. "support@quadrique.com" or "support@quadrique.com;sales@quadrique.com")
Throws:
Exception

setBody

public void setBody(DataSource body)
To set the body of the email

Parameters:
body - a DataSource isntance

setBodyPlainText

public void setBodyPlainText(File body)
                      throws Exception
To set the body of the email from the content of a file
The file content is assumed to be plain text.

Parameters:
body - the file
Throws:
Exception

setBodyHtml

public void setBodyHtml(File body)
                 throws Exception
To set the body of the email from the content of a file
The file content is assumed to be HTML.

Parameters:
body - the file
Throws:
Exception

setBody

public void setBody(File body,
                    String contentType)
             throws Exception
To set the body of the email from the content of a file.
If the file content is plain HTML, you can directly use the setBody(File file) method

Parameters:
contentType - the content type of the file (e.g. "text/html; charset="iso-8859-1"").
Please note that the syntax of this field is defined in RFC 2045
body - the file
Throws:
Exception

setBodyHtml

public void setBodyHtml(String body)
                 throws Exception
To set the body of the email from the content of a String
The String content is assumed to be HTML.

Parameters:
body - the String
Throws:
Exception

setBodyPlainText

public void setBodyPlainText(String body)
                      throws Exception
To set the body of the email from the content of a String
The String content is assumed to be plain text.

Parameters:
body - the String
Throws:
Exception

setBody

public void setBody(String body,
                    String contentType)
             throws Exception
To set the body of the email from the content of a String.
If the String content is plain HTML, you can directly use the setBody(String body) method

Parameters:
contentType - the content type of the String (e.g. "text/html; charset="iso-8859-1"").
Please note that the syntax of this field is defined in RFC 2045
body - the String
Throws:
Exception

setFrom

public void setFrom(String from)
             throws Exception
Parameters:
from - The 'from' address to use
Throws:
Exception

getFrom

public String getFrom()
Returns:
Returns the 'from' address.

sendEmail

public void sendEmail()
               throws Exception
Throws:
Exception

sendEmailWithAttachments

public void sendEmailWithAttachments(ArrayList<File> files)
                              throws Exception
Parameters:
files -
Throws:
Exception

sendEmailHtmlWithEmbeddedImages

public void sendEmailHtmlWithEmbeddedImages(HashMap<String,File> images)
                                     throws Exception
HTML email messages with image links (e.g. ) are considered harmful and tend to be blocked by default by most anti-virus programs (it's an easy way for a spammer to determine if your email is valid and if you are reading your emails :)). The following method allows to send HTML emails with embedded images. Here is a sample code snippet: emailHandler.setBodyHtml("

Here is an image: "); HashMap map = new HashMap(); map.put("image1",new File("C:\\Data\\Societe\\Quadrique\\Products\\JBuildingBlocks\\TestData\\email\\sampleImage.jpg")); emailHandler.sendEmailHtmlWithEmbeddedImages(map); Please note that in order to make it work, your img HTML tag is of the form where "cid" stands for content id and "image1" refers to the key in the HashMap

Parameters:
images -
Throws:
Exception

getBcc

public ArrayList<String> getBcc()
Returns:
Returns the bcc.

getBody

public DataSource getBody()
Returns:
Returns the body.

getCc

public ArrayList<String> getCc()
Returns:
Returns the cc.

getSession

public javax.mail.Session getSession()
Returns:
Returns the session.

getSubject

public String getSubject()
Returns:
Returns the subject.

setSubject

public void setSubject(String subject)
Parameters:
subject - The subject to set.

getTo

public ArrayList<String> getTo()
Returns:
Returns the to.

isValidateEmailAddresses

public boolean isValidateEmailAddresses()
Returns:
Returns the emailAddressValidation.

setValidateEmailAddresses

public void setValidateEmailAddresses(boolean emailAddressValidation)
Parameters:
emailAddressValidation - The emailAddressValidation to set.

convertEmailAddressListFromArrayListToString

public String convertEmailAddressListFromArrayListToString(ArrayList<String> liste)
                                                    throws Exception
Parameters:
liste -
Returns:
a semicolon separated list of email addresses (e.g. "sales@quadrique.com;support@quadrique.com")
Throws:
Exception

openPOP3Connection

public void openPOP3Connection()
                        throws Exception
Before doing anything with a POP3 server, call this method to establish the connection.

Throws:
Exception

closePOP3Connection

public void closePOP3Connection()
                         throws Exception
This must be called once all interaction with the POP3 server and its messages has been completed.

Throws:
Exception

retrieveEmailFromPOP3Server

public ArrayList<javax.mail.Message> retrieveEmailFromPOP3Server(boolean leaveCopyOnServer)
                                                          throws Exception
Retrieve email messages from a POP3 server

Parameters:
leaveCopyOnServer - Set to true if the messages should be left on the server
Returns:
list of messages
Throws:
Exception
See Also:
openPOP3Connection(), closePOP3Connection()


Copyright © 2001-2008 Quadrique Corporation. All Rights Reserved.