org.opennms.netmgt.utils
Class JavaMailer

java.lang.Object
  extended by org.opennms.netmgt.utils.JavaMailer

public class JavaMailer
extends Object

Sends an email message using the Java Mail API

Author:
David Hustace

Nested Class Summary
static class JavaMailer.LoggingByteArrayOutputStream
           
static class JavaMailer.LoggingTransportListener
           
 
Constructor Summary
JavaMailer()
          Default constructor.
JavaMailer(Properties javamailProps)
           
 
Method Summary
 Message buildMessage()
          Build a complete message ready for sending.
 Authenticator createAuthenticator()
          Helper method to create an Authenticator based on Password Authentication
 MimeBodyPart createFileAttachment(File file)
          Create a file attachment as a MimeBodyPart, checking to see if the file exists before we create the attachment.
 String getCharSet()
           
 String getContentType()
           
 String getEncoding()
           
 String getFileName()
           
 String getFrom()
           
 String getMailer()
           
 String getMailHost()
           
 Properties getMailProps()
          This returns the properties configured in the javamail-configuration.properties file.
 String getMessageText()
           
 String getPassword()
           
 Session getSession()
           
 int getSmtpPort()
           
 String getSubject()
           
 String getTo()
           
 String getTransport()
           
 String getUser()
           
 boolean isAuthenticate()
           
 boolean isDebug()
           
 boolean isQuitWait()
           
 boolean isSmtpSsl()
           
 boolean isStartTlsEnabled()
           
 boolean isUseJMTA()
           
 void mailSend()
          Sends a message based on properties set on this bean.
 void sendMessage(Message message)
          Send message.
 void setAuthenticate(boolean authenticate)
           
 void setCharSet(String charSet)
           
 void setContentType(String contentType)
           
 void setDebug(boolean debug)
           
 void setEncoding(String encoding)
           
 void setFileName(String fileName)
           
 void setFrom(String from)
           
 void setMailer(String mailer)
           
 void setMailHost(String mail_host)
           
 void setMessageText(String messageText)
           
 void setPassword(String password)
           
 void setQuitWait(boolean quitWait)
           
 void setSession(Session session)
           
 void setSmtpPort(int smtpPort)
           
 void setSmtpSsl(boolean smtpSsl)
           
 void setStartTlsEnabled(boolean startTlsEnabled)
           
 void setSubject(String subject)
           
 void setTo(String to)
           
 void setTransport(String transport)
           
 void setUseJMTA(boolean useMTA)
           
 void setUser(String user)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaMailer

public JavaMailer(Properties javamailProps)
           throws JavaMailerException
Throws:
JavaMailerException

JavaMailer

public JavaMailer()
           throws JavaMailerException
Default constructor. Default properties from javamailer-properties are set into session. To change these properties, retrieve the current properties from the session and override as needed.

Throws:
IOException
JavaMailerException
Method Detail

mailSend

public void mailSend()
              throws JavaMailerException
Sends a message based on properties set on this bean.

Throws:
JavaMailerException

createAuthenticator

public Authenticator createAuthenticator()
Helper method to create an Authenticator based on Password Authentication

Returns:

buildMessage

public Message buildMessage()
                     throws JavaMailerException
Build a complete message ready for sending.

Parameters:
session - session to use to create a new MimeMessage
Returns:
completed message, ready to be passed to Transport.sendMessage
Throws:
JavaMailerException - if any of the underlying operations fail

createFileAttachment

public MimeBodyPart createFileAttachment(File file)
                                  throws MessagingException,
                                         JavaMailerException
Create a file attachment as a MimeBodyPart, checking to see if the file exists before we create the attachment.

Parameters:
file - file to attach
Returns:
attachment body part
Throws:
MessagingException - if we can't set the data handler or the file name on the MimeBodyPart
JavaMailerException - if the file does not exist or is not readable

sendMessage

public void sendMessage(Message message)
                 throws JavaMailerException
Send message.

Parameters:
session -
message -
Throws:
JavaMailerException

getPassword

public String getPassword()
Returns:
Returns the password.

setPassword

public void setPassword(String password)
Parameters:
password - The password to set.

getUser

public String getUser()
Returns:
Returns the user.

setUser

public void setUser(String user)
Parameters:
user - The user to set.

isUseJMTA

public boolean isUseJMTA()
Returns:
Returns the _useMailHost.

setUseJMTA

public void setUseJMTA(boolean useMTA)
Parameters:
mailHost - The _useMailHost to set.

getFrom

public String getFrom()
Returns:
Returns the from address.

setFrom

public void setFrom(String from)
Parameters:
from - The from address to set.

isAuthenticate

public boolean isAuthenticate()
Returns:
Returns the authenticate boolean.

setAuthenticate

public void setAuthenticate(boolean authenticate)
Parameters:
authenticate - The authenticate boolean to set.

getFileName

public String getFileName()
Returns:
Returns the file name attachment.

setFileName

public void setFileName(String fileName)
Parameters:
file - Sets the file name to be attached to the messaget.

getMailHost

public String getMailHost()
Returns:
Returns the mail host.

setMailHost

public void setMailHost(String mail_host)
Parameters:
mail_host - Sets the mail host.

getMailer

public String getMailer()
Returns:
Returns the mailer.

setMailer

public void setMailer(String mailer)
Parameters:
mailer - Sets the mailer.

getMessageText

public String getMessageText()
Returns:
Returns the message text.

setMessageText

public void setMessageText(String messageText)
Parameters:
messageText - Sets the message text.

getSubject

public String getSubject()
Returns:
Returns the message Subject.

setSubject

public void setSubject(String subject)
Parameters:
subject - Sets the message Subject.

getTo

public String getTo()
Returns:
Returns the To address.

setTo

public void setTo(String to)
Parameters:
to - Sets the To address.

getTransport

public String getTransport()

setTransport

public void setTransport(String transport)

isDebug

public boolean isDebug()

setDebug

public void setDebug(boolean debug)

getSession

public Session getSession()
Returns:
the session

setSession

public void setSession(Session session)
Parameters:
session - the session to set

getContentType

public String getContentType()
Returns:
the contentType

setContentType

public void setContentType(String contentType)
Parameters:
contentType - the contentType to set

getCharSet

public String getCharSet()
Returns:
the charSet

setCharSet

public void setCharSet(String charSet)
Parameters:
charSet - the charSet to set

getEncoding

public String getEncoding()
Returns:
the encoding

setEncoding

public void setEncoding(String encoding)
Parameters:
encoding - the encoding to set

isStartTlsEnabled

public boolean isStartTlsEnabled()
Returns:
the startTlsEnabled

setStartTlsEnabled

public void setStartTlsEnabled(boolean startTlsEnabled)
Parameters:
startTlsEnabled - the startTlsEnabled to set

isQuitWait

public boolean isQuitWait()
Returns:
the quitWait

setQuitWait

public void setQuitWait(boolean quitWait)
Parameters:
quitWait - the quitWait to set

getSmtpPort

public int getSmtpPort()
Returns:
the smtpPort

setSmtpPort

public void setSmtpPort(int smtpPort)
Parameters:
smtpPort - the smtpPort to set

isSmtpSsl

public boolean isSmtpSsl()
Returns:
the smtpSsl

setSmtpSsl

public void setSmtpSsl(boolean smtpSsl)
Parameters:
smtpSsl - the smtpSsl to set

getMailProps

public Properties getMailProps()
This returns the properties configured in the javamail-configuration.properties file.

Returns:


Copyright © 2009. All Rights Reserved.