com.emarsys.ecommon.mail
Class JMailFactory

java.lang.Object
  extended by com.emarsys.ecommon.mail.JMailFactory

public class JMailFactory
extends java.lang.Object

A factory for JavaMail(tm) Messages.

Author:
Michael "kULO" Kulovits

Field Summary
protected  javax.mail.Multipart mainPart
           
protected  javax.mail.internet.MimeMessage message
           
protected  javax.mail.Session session
           
protected  javax.mail.internet.MimeBodyPart textPart
           
 
Constructor Summary
JMailFactory()
          Creates a new JMailFactory with a default Session driven by the System Properties.
JMailFactory(java.util.Properties settings)
          Creates a new JMailFactory with a Session driven by the passed Properties.
JMailFactory(javax.mail.Session session)
          Creates a new JMailFactory instance associated with the passed JavaMail Session.
 
Method Summary
 JMailFactory addAttachment(java.io.ByteArrayOutputStream stream, java.lang.String fileName)
           
 JMailFactory addAttachment(java.io.File file)
           
 JMailFactory addBCC(java.lang.String bcc)
          Adds the passed BCC recipient to this Message.
 JMailFactory addBCCs(java.lang.String bccs)
          Adds the passed BCC recipients to this Message.
 JMailFactory addCC(java.lang.String cc)
          Adds the passed CC recipient to this Message.
 JMailFactory addCCs(java.lang.String ccs)
          Adds the passed CC recipients to this Message.
 JMailFactory addTO(java.lang.String to)
          Add the passed TO recipient to this Message.
 JMailFactory addTOs(java.lang.String tos)
          Adds the passed TO recipients to this Message.
 javax.mail.Address[] getFrom()
           
static JMailFactory getInstance(java.util.Properties props)
          A factory method which might create specific JMailFactory instances according to the Properties passed.
protected  java.lang.String getMailEncoding()
           
 javax.mail.Message getMessage()
           
 byte[] getMessageBytes()
           
 javax.mail.Address[] getRecipients(javax.mail.Message.RecipientType type)
           
 javax.mail.Address[] getReplyTo()
           
 boolean hasFrom()
           
 boolean hasText()
           
protected  void init()
           
protected  boolean isMailEncodingSet()
           
 JMailFactory setFrom(javax.mail.Address from)
           
 JMailFactory setFrom(java.lang.String from)
           
 JMailFactory setReplyTos(javax.mail.Address[] replyTos)
          Adds the passed REPLY-TO Addresses to this Message.
 JMailFactory setReplyTos(java.lang.String replyTos)
          Adds the passed REPLY-TO addresses to this Message.
 JMailFactory setSubject(java.lang.String subject)
           
 JMailFactory setText(java.lang.String msg)
           
protected static void splitAddressesAndPerform(java.lang.String addresses, Closure<java.lang.String> closure)
          Splits the passed addresses on commas and performs the passed Closure on the splitted Strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

protected javax.mail.Session session

message

protected javax.mail.internet.MimeMessage message

mainPart

protected javax.mail.Multipart mainPart

textPart

protected javax.mail.internet.MimeBodyPart textPart
Constructor Detail

JMailFactory

public JMailFactory(java.util.Properties settings)
             throws javax.mail.MessagingException,
                    java.lang.IllegalArgumentException
Creates a new JMailFactory with a Session driven by the passed Properties.

Parameters:
props -
Throws:
javax.mail.MessagingException
java.lang.IllegalArgumentException

JMailFactory

public JMailFactory()
             throws javax.mail.MessagingException
Creates a new JMailFactory with a default Session driven by the System Properties.

Throws:
javax.mail.MessagingException
See Also:
#JMailFactory(Properties)}

JMailFactory

public JMailFactory(javax.mail.Session session)
             throws javax.mail.MessagingException,
                    java.lang.IllegalArgumentException
Creates a new JMailFactory instance associated with the passed JavaMail Session.

Parameters:
session -
Throws:
javax.mail.MessagingException
java.lang.IllegalArgumentException
Method Detail

getInstance

public static JMailFactory getInstance(java.util.Properties props)
                                throws javax.mail.MessagingException
A factory method which might create specific JMailFactory instances according to the Properties passed.

Parameters:
props -
Returns:
a new JMailFactory instance that will be initialized with the passed Properties.
Throws:
javax.mail.MessagingException

splitAddressesAndPerform

protected static void splitAddressesAndPerform(java.lang.String addresses,
                                               Closure<java.lang.String> closure)
Splits the passed addresses on commas and performs the passed Closure on the splitted Strings.

Parameters:
addresses - - a comma ',' seperated list of email addresses
closure - - the function to execute on each of the splitted addresses

init

protected void init()
             throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

getMessage

public javax.mail.Message getMessage()
                              throws java.lang.IllegalArgumentException,
                                     javax.mail.internet.AddressException,
                                     javax.mail.MessagingException
Returns:
Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException
java.lang.IllegalArgumentException

getMessageBytes

public byte[] getMessageBytes()
                       throws javax.mail.internet.AddressException,
                              java.lang.IllegalArgumentException,
                              java.io.IOException,
                              javax.mail.MessagingException
Returns:
Throws:
javax.mail.MessagingException
java.io.IOException
java.lang.IllegalArgumentException
javax.mail.internet.AddressException

addTO

public JMailFactory addTO(java.lang.String to)
                   throws javax.mail.internet.AddressException,
                          javax.mail.MessagingException
Add the passed TO recipient to this Message.

Parameters:
to - - the email address of the TO recipient
Returns:
this JMailFactory.
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

addTOs

public JMailFactory addTOs(java.lang.String tos)
                    throws javax.mail.internet.AddressException,
                           javax.mail.MessagingException
Adds the passed TO recipients to this Message.

Parameters:
to - String of e-mail-adresses separated by ','
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

addCC

public JMailFactory addCC(java.lang.String cc)
                   throws javax.mail.internet.AddressException,
                          javax.mail.MessagingException
Adds the passed CC recipient to this Message.

Parameters:
cc -
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

addCCs

public JMailFactory addCCs(java.lang.String ccs)
                    throws javax.mail.internet.AddressException,
                           javax.mail.MessagingException
Adds the passed CC recipients to this Message.

Parameters:
to - String of e-mail-adresses separated by ','
Returns:
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

addBCC

public JMailFactory addBCC(java.lang.String bcc)
                    throws javax.mail.internet.AddressException,
                           javax.mail.MessagingException
Adds the passed BCC recipient to this Message.

Parameters:
bcc -
Returns:
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

addBCCs

public JMailFactory addBCCs(java.lang.String bccs)
                     throws javax.mail.internet.AddressException,
                            javax.mail.MessagingException
Adds the passed BCC recipients to this Message.

Parameters:
to - String of e-mail-adresses separated by ','
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

setReplyTos

public JMailFactory setReplyTos(java.lang.String replyTos)
                         throws javax.mail.internet.AddressException,
                                javax.mail.MessagingException
Adds the passed REPLY-TO addresses to this Message.

Parameters:
to - String of e-mail-adresses separated by ','
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

setReplyTos

public JMailFactory setReplyTos(javax.mail.Address[] replyTos)
                         throws javax.mail.MessagingException
Adds the passed REPLY-TO Addresses to this Message.

Parameters:
replyTos -
Throws:
javax.mail.MessagingException

setFrom

public JMailFactory setFrom(java.lang.String from)
                     throws javax.mail.internet.AddressException,
                            javax.mail.MessagingException
Parameters:
from -
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

setFrom

public JMailFactory setFrom(javax.mail.Address from)
                     throws javax.mail.MessagingException
Parameters:
from -
Returns:
Throws:
javax.mail.MessagingException

hasFrom

public boolean hasFrom()
                throws javax.mail.internet.AddressException,
                       java.lang.IllegalArgumentException,
                       javax.mail.MessagingException
Returns:
Throws:
javax.mail.MessagingException
java.lang.IllegalArgumentException
javax.mail.internet.AddressException

setSubject

public JMailFactory setSubject(java.lang.String subject)
                        throws javax.mail.MessagingException
Parameters:
subject -
Throws:
javax.mail.MessagingException

setText

public JMailFactory setText(java.lang.String msg)
                     throws javax.mail.MessagingException
Parameters:
msg -
Throws:
javax.mail.MessagingException

hasText

public boolean hasText()
Returns:

addAttachment

public JMailFactory addAttachment(java.io.File file)
                           throws javax.mail.MessagingException,
                                  java.io.FileNotFoundException
Parameters:
file -
Throws:
javax.mail.MessagingException
java.io.FileNotFoundException

addAttachment

public JMailFactory addAttachment(java.io.ByteArrayOutputStream stream,
                                  java.lang.String fileName)
                           throws javax.mail.MessagingException
Parameters:
stream -
fileName -
Throws:
javax.mail.MessagingException

getFrom

public javax.mail.Address[] getFrom()
                             throws javax.mail.MessagingException
Returns:
Throws:
javax.mail.MessagingException

getRecipients

public javax.mail.Address[] getRecipients(javax.mail.Message.RecipientType type)
                                   throws javax.mail.MessagingException
Parameters:
type -
Returns:
Throws:
javax.mail.MessagingException

getReplyTo

public javax.mail.Address[] getReplyTo()
                                throws javax.mail.MessagingException
Returns:
Throws:
javax.mail.MessagingException

getMailEncoding

protected java.lang.String getMailEncoding()
Returns:

isMailEncodingSet

protected boolean isMailEncodingSet()
Returns:


Copyright © 2010 emarsys AG. All Rights Reserved.