Package edu.uiuc.ncsa.security.util.mail
Class MailUtil
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.mail.MailUtil
-
- All Implemented Interfaces:
Logable
,MailUtilInterface
- Direct Known Subclasses:
ServletMailUtil
public class MailUtil extends Object implements MailUtilInterface
A utility for sending messages via SMTP or SMTPS using Java mail. A MailUtil object contains a complete configuration for sending messages.Created by Jeff Gaynor
on 10/5/11 at 1:18 PM
-
-
Constructor Summary
Constructors Constructor Description MailUtil()
MailUtil(MyLoggingFacade myLogger)
MailUtil(MailEnvironment me)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
debug(String x)
Write a debug message to the log.void
error(String x)
Write an error message to the log.void
error(String x, Throwable t)
MailEnvironment
getMailEnvironment()
String
getMessageTemplate()
MyLoggingFacade
getMyLogger()
javax.mail.Session
getSession(Properties props)
String
getSubjectTemplate()
void
info(String x)
Write an informational message to the logboolean
isDebugOn()
Query if debugging is enabled for this logger.boolean
isEnabled()
boolean
NEWsendMessage(String subjectTemplate, String messageTemplate, Map replacements, String newRecipients)
protected String
readTemplate(String fileName)
boolean
sendMessage(String subjectTemplate, String messageTemplate, Map replacements)
boolean
sendMessage(String subjectTemplate, String messageTemplate, Map replacements, String newRecipients)
This allows for sending with a specific subject and message template.boolean
sendMessage(Map replacements)
This takes a map of replacements for the templates and sends the message.void
setDebugOn(boolean debugOn)
Enable/disable debugging for this loggervoid
setMessageTemplate(String messageTemplate)
void
setMyLogger(MyLoggingFacade myLogger)
void
setSubjectTemplate(String subjectTemplate)
void
warn(String x)
Write a warning to the log.
-
-
-
Constructor Detail
-
MailUtil
public MailUtil(MyLoggingFacade myLogger)
-
MailUtil
public MailUtil()
-
MailUtil
public MailUtil(MailEnvironment me)
-
-
Method Detail
-
getSession
public javax.mail.Session getSession(Properties props) throws NamingException
- Throws:
NamingException
-
isEnabled
public boolean isEnabled()
- Specified by:
isEnabled
in interfaceMailUtilInterface
-
getMailEnvironment
public MailEnvironment getMailEnvironment()
- Specified by:
getMailEnvironment
in interfaceMailUtilInterface
-
sendMessage
public boolean sendMessage(String subjectTemplate, String messageTemplate, Map replacements)
- Specified by:
sendMessage
in interfaceMailUtilInterface
-
sendMessage
public boolean sendMessage(String subjectTemplate, String messageTemplate, Map replacements, String newRecipients)
This allows for sending with a specific subject and message template. This is useful for internally generated messages that may need a lot of customization on the fly. Remember that a template has string delimited with ${KEY} which the replacements map (KEY, VALUE pairs) will render into VALUES.- Specified by:
sendMessage
in interfaceMailUtilInterface
- Parameters:
subjectTemplate
-messageTemplate
-replacements
-- Returns:
-
NEWsendMessage
public boolean NEWsendMessage(String subjectTemplate, String messageTemplate, Map replacements, String newRecipients)
-
sendMessage
public boolean sendMessage(Map replacements)
This takes a map of replacements for the templates and sends the message.This will return a true if the message succeeded and a false otherwise. It will not cause a failure outright, since a failed notification should not bring down your server.
- Specified by:
sendMessage
in interfaceMailUtilInterface
- Parameters:
replacements
-- Returns:
-
getMessageTemplate
public String getMessageTemplate() throws IOException
- Throws:
IOException
-
setMessageTemplate
public void setMessageTemplate(String messageTemplate)
-
setSubjectTemplate
public void setSubjectTemplate(String subjectTemplate)
-
getSubjectTemplate
public String getSubjectTemplate() throws IOException
- Throws:
IOException
-
readTemplate
protected String readTemplate(String fileName) throws IOException
- Throws:
IOException
-
getMyLogger
public MyLoggingFacade getMyLogger()
-
setMyLogger
public void setMyLogger(MyLoggingFacade myLogger)
-
debug
public void debug(String x)
Description copied from interface:Logable
Write a debug message to the log.
-
setDebugOn
public void setDebugOn(boolean debugOn)
Description copied from interface:Logable
Enable/disable debugging for this logger- Specified by:
setDebugOn
in interfaceLogable
-
isDebugOn
public boolean isDebugOn()
Description copied from interface:Logable
Query if debugging is enabled for this logger.
-
info
public void info(String x)
Description copied from interface:Logable
Write an informational message to the log
-
warn
public void warn(String x)
Description copied from interface:Logable
Write a warning to the log. This indicates a severe, but non-fatal condition exists.
-
error
public void error(String x)
Description copied from interface:Logable
Write an error message to the log. Typically this is invoked as the last command before throwing an exception.
-
-