org.umber.core.email
Class EmailFactory
java.lang.Object
org.umber.core.email.EmailFactory
- public class EmailFactory
- extends java.lang.Object
Instantiator for email implementations.
- Author:
- jsheets
Method Summary |
static void |
checkDependencies()
Ensures that all JavaMail dependencies are available on the CLASSPATH. |
static IEmailManager |
getEmail(java.util.Map properties)
Instantiates an email manager. |
static IEmailManager |
getEmail(java.lang.String path)
Instantiates an email manager from the properties file at the given path
on the CLASSPATH. |
static boolean |
isDebug()
|
static boolean |
isJavaMailAvailable()
Determines if a JavaMail implementation is available on the classpath. |
static void |
main(java.lang.String[] args)
Diagnostic method to test invocation of isVelocityAvailable(),
getRunner(), and new VelocityRunner(). |
static void |
setDebug(boolean debug)
Sets email debug mode. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
isDebug
public static boolean isDebug()
setDebug
public static void setDebug(boolean debug)
- Sets email debug mode. A value of true activates debug mode, which
prevents all email activity from going through the JavaMail API;
false deactivates debug mode, causing all email traffic to use the
JavaMail API. By default, debug mode is false.
Debug mode is useful for unit-testing Umber components and applications
that use the Umber email API.
- Parameters:
debug
- true to activate debug mode; false to deactivate
checkDependencies
public static void checkDependencies()
throws UmberClassException
- Ensures that all JavaMail dependencies are available on the CLASSPATH.
Returns quietly if all dependencies exist; throws an exception with
a description of missing libraries.
- Throws:
UmberClassException
- if a JavaMail dependency is missing
isJavaMailAvailable
public static boolean isJavaMailAvailable()
- Determines if a JavaMail implementation is available on the classpath.
- Returns:
- true if JavaMail is on classpath
getEmail
public static IEmailManager getEmail(java.util.Map properties)
throws UmberEmailException
- Instantiates an email manager. If setDebug() has been called with a
true, returns DebugEmailManager; if JavaMail is available on the
CLASSPATH, returns JavaMailEmailManager; otherwise, throws an exception.
The properties define the email connection parameters.
The properties match
JavaMail properties):
Protocol Properties
- mail.store.protocol - the protocol for retrieving messages:
"pop3" or "imap"
Default Properties For All Protocols
- mail.host - default server name for sending and receiving emails
- mail.port - default server port for sending and receiving emails
- mail.user - default user name for connecting to mail servers
- mail.password - default password for connecting to mail servers
SMTP Properties
- mail.smtp.host - server name for sending emails
- mail.smtp.port - server port for sending emails
- mail.smtp.user - user name for connecting to the SMTP server
- mail.smtp.password - password for connecting to the SMTP server
POP3 Properties
- mail.pop3.host - server name for receiving emails via POP3
- mail.pop3.port - server port for receiving emails via POP3
- mail.pop3.user - user name for connecting to the POP3 server
- mail.pop3.password - password for connecting to the POP3 server
IMAP Properties
- mail.imap.host - server name for receiving emails via IMAP
- mail.imap.port - server port for receiving emails via IMAP
- mail.imap.user - user name for connecting to the IMAP server
- mail.imap.password - password for connecting to the IMAP server
Finally to use an alternate, custom implementation of IEmailManager,
you can set the property mail.manager.class to the fully qualified
class of the implementation. If that class is not found, or cannot be
instantiated, this method will throw an exception.
- Parameters:
properties
- email connection properties, can be Map or Properties
- Returns:
- email manager instance
- Throws:
UmberEmailException
- if unable to instantiate an email manager
getEmail
public static IEmailManager getEmail(java.lang.String path)
throws UmberEmailException
- Instantiates an email manager from the properties file at the given path
on the CLASSPATH. The properties define the email connection parameters.
- Parameters:
path
- path to email connection properties file, on CLASSPATH
- Returns:
- email manager instance
- Throws:
UmberEmailException
- if unable to instantiate an email manager- See Also:
getEmail(Map)
main
public static void main(java.lang.String[] args)
- Diagnostic method to test invocation of isVelocityAvailable(),
getRunner(), and new VelocityRunner().
- Parameters:
args
- command-line arguments