org.kuali.rice.kew.mail
Class Mailer

java.lang.Object
  extended by org.kuali.rice.kew.mail.Mailer

public class Mailer
extends Object

Maintains a Java Mail session and can be used for sending emails.

Author:
Kuali Rice Team (rice.collab@kuali.org)

Nested Class Summary
private static class Mailer.SimpleAuthenticator
          SimpleAuthenticator is used to do simple authentication when the SMTP server requires it.
 
Field Summary
private  javax.mail.Authenticator authenticator
           
private  Properties configProperties
           
private  javax.mail.Session currentSession
           
protected  org.apache.log4j.Logger LOG
           
 
Constructor Summary
Mailer(Properties configProperties)
           
Mailer(Properties configProperties, javax.mail.Authenticator authenticator)
          Create a AuthenticatedMailer with the default values for authenticated use of mail-relay.iu.edu.
Mailer(Properties configProperties, String username, String password)
           
 
Method Summary
 javax.mail.Authenticator getAuthenticator()
           
 Properties getConfig()
           
 javax.mail.Session getCurrentSession()
          This allows direct access to the Mail Session.
private  void prepareHtmlMessage(String messageText, javax.mail.Message message)
           
 void sendMessage(String sender, javax.mail.Address[] recipients, String subject, String messageBody, javax.mail.Address[] ccRecipients, javax.mail.Address[] bccRecipients, boolean htmlMessage)
          Sends an email to the given recipients.
 void sendMessage(String sender, String recipient, String subject, String messageBody, boolean htmlMessage)
          Send a message to the designated recipient with the specified subject and message.
 void setConfig(Properties configProperties)
          A method to configure the Mailer properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected final org.apache.log4j.Logger LOG

configProperties

private Properties configProperties

authenticator

private javax.mail.Authenticator authenticator

currentSession

private javax.mail.Session currentSession
Constructor Detail

Mailer

public Mailer(Properties configProperties,
              javax.mail.Authenticator authenticator)
Create a AuthenticatedMailer with the default values for authenticated use of mail-relay.iu.edu. The Kerberos principle and and password should be a system principle rather than a user principle.

Parameters:
senderAddress - return address for the mail being sent
kbPrincipleName - kerberos principle name used to authenticate to mail-relay
kbPrinciplePassword - kerberos principle password used to authenticate to mail-relay

Mailer

public Mailer(Properties configProperties)

Mailer

public Mailer(Properties configProperties,
              String username,
              String password)
Method Detail

setConfig

public void setConfig(Properties configProperties)
A method to configure the Mailer properties. This class will default to a set of properties but this method allows the calling program to set the specific properties.

Parameters:
mailConfigProperties - Proeprties object containing configuration information

sendMessage

public void sendMessage(String sender,
                        javax.mail.Address[] recipients,
                        String subject,
                        String messageBody,
                        javax.mail.Address[] ccRecipients,
                        javax.mail.Address[] bccRecipients,
                        boolean htmlMessage)
                 throws javax.mail.internet.AddressException,
                        javax.mail.MessagingException
Sends an email to the given recipients.

Parameters:
recipients - list of addresses to which the message is sent
subject - subject of the message
messageBody - body of the message
ccRecipients - list of addresses which are to be cc'd on the message
bccRecipients - list of addresses which are to be bcc'd on the message
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

sendMessage

public void sendMessage(String sender,
                        String recipient,
                        String subject,
                        String messageBody,
                        boolean htmlMessage)
                 throws javax.mail.internet.AddressException,
                        javax.mail.MessagingException
Send a message to the designated recipient with the specified subject and message. This is a convience class for simple message addressing

Parameters:
recipient - the email address to which the message is sent
subject - subject for the message
messageBody - body of the message to to be sent
ccRecipient - email address of a cc recipient
Throws:
javax.mail.internet.AddressException
javax.mail.MessagingException

getConfig

public Properties getConfig()
Returns:
current properties used to configure the mail session

getAuthenticator

public javax.mail.Authenticator getAuthenticator()

getCurrentSession

public javax.mail.Session getCurrentSession()
                                     throws javax.mail.NoSuchProviderException
This allows direct access to the Mail Session. While this offers more flexibility, the AuthenticatedMailer will no longer be responsible for management of the this session.

Returns:
get the current session. If current session is null it creates a new one.
Throws:
javax.mail.NoSuchProviderException

prepareHtmlMessage

private void prepareHtmlMessage(String messageText,
                                javax.mail.Message message)
                         throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.