Package edu.uiuc.ncsa.security.util.mail
Class JakartaMailUtil
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.mail.JakartaMailUtil
-
- All Implemented Interfaces:
Logable,MailUtilInterface
public class JakartaMailUtil 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 JakartaMailUtil()JakartaMailUtil(MyLoggingFacade myLogger)JakartaMailUtil(MailEnvironment me)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddebug(String x)Write a debug message to the log.voiderror(String x)Write an error message to the log.voiderror(String x, Throwable t)MailEnvironmentgetMailEnvironment()StringgetMessageTemplate()MyLoggingFacadegetMyLogger()jakarta.mail.SessiongetSession(Properties props)StringgetSubjectTemplate()voidinfo(String x)Write an informational message to the logbooleanisDebugOn()Query if debugging is enabled for this logger.booleanisEnabled()booleanNEWsendMessage(String subjectTemplate, String messageTemplate, Map replacements, String newRecipients)protected StringreadTemplate(String fileName)booleansendMessage(String subjectTemplate, String messageTemplate, Map replacements)booleansendMessage(String subjectTemplate, String messageTemplate, Map replacements, String newRecipients)This allows for sending with a specific subject and message template.booleansendMessage(Map replacements)This takes a map of replacements for the templates and sends the message.voidsetDebugOn(boolean debugOn)Enable/disable debugging for this loggervoidsetMessageTemplate(String messageTemplate)voidsetMyLogger(MyLoggingFacade myLogger)voidsetSubjectTemplate(String subjectTemplate)voidwarn(String x)Write a warning to the log.
-
-
-
Constructor Detail
-
JakartaMailUtil
public JakartaMailUtil(MyLoggingFacade myLogger)
-
JakartaMailUtil
public JakartaMailUtil()
-
JakartaMailUtil
public JakartaMailUtil(MailEnvironment me)
-
-
Method Detail
-
getSession
public jakarta.mail.Session getSession(Properties props) throws NamingException
- Throws:
NamingException
-
isEnabled
public boolean isEnabled()
- Specified by:
isEnabledin interfaceMailUtilInterface
-
getMailEnvironment
public MailEnvironment getMailEnvironment()
- Specified by:
getMailEnvironmentin interfaceMailUtilInterface
-
sendMessage
public boolean sendMessage(String subjectTemplate, String messageTemplate, Map replacements)
- Specified by:
sendMessagein 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:
sendMessagein 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:
sendMessagein 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:LogableWrite a debug message to the log.
-
setDebugOn
public void setDebugOn(boolean debugOn)
Description copied from interface:LogableEnable/disable debugging for this logger- Specified by:
setDebugOnin interfaceLogable
-
isDebugOn
public boolean isDebugOn()
Description copied from interface:LogableQuery if debugging is enabled for this logger.
-
info
public void info(String x)
Description copied from interface:LogableWrite an informational message to the log
-
warn
public void warn(String x)
Description copied from interface:LogableWrite a warning to the log. This indicates a severe, but non-fatal condition exists.
-
error
public void error(String x)
Description copied from interface:LogableWrite an error message to the log. Typically this is invoked as the last command before throwing an exception.
-
-