org.opennms.javamail
Class JavaMailer

java.lang.Object
  extended by org.opennms.javamail.JavaMailer

public class JavaMailer
extends Object

Sends an email message using the Java Mail API

Version:
$Id: $
Author:
David Hustace

Nested Class Summary
static class JavaMailer.LoggingByteArrayOutputStream
           
static class JavaMailer.LoggingTransportListener
           
 
Constructor Summary
JavaMailer()
          Default constructor.
JavaMailer(Properties javamailProps)
          Constructor for JavaMailer.
 
Method Summary
 void addExtraHeader(String key, String value)
           
 javax.mail.Message buildMessage()
          Build a complete message ready for sending.
 javax.mail.Authenticator createAuthenticator()
          Helper method to create an Authenticator based on Password Authentication
 javax.mail.internet.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()
          getCharSet
 String getContentType()
          getContentType
 String getEncoding()
          getEncoding
 Map<String,String> getExtraHeaders()
           
 String getFileName()
          getFileName
 String getFrom()
          getFrom
 InputStream getInputStream()
          getInputStream
 String getInputStreamContentType()
          getInputStreamContentType
 String getInputStreamName()
          getInputStreamName
 String getMailer()
          getMailer
 String getMailHost()
          getMailHost
 Properties getMailProps()
          This returns the properties configured in the javamail-configuration.properties file.
 String getMessageText()
          getMessageText
 String getPassword()
          getPassword
 javax.mail.Session getSession()
          getSession
 int getSmtpPort()
          getSmtpPort
 String getSubject()
          getSubject
 String getTo()
          getTo
 String getTransport()
          getTransport
 String getUser()
          getUser
 boolean isAuthenticate()
          isAuthenticate
 boolean isDebug()
          isDebug
 boolean isQuitWait()
          isQuitWait
 boolean isSmtpSsl()
          isSmtpSsl
 boolean isStartTlsEnabled()
          isStartTlsEnabled
 boolean isUseJMTA()
          isUseJMTA
 void mailSend()
          Sends a message based on properties set on this bean.
 void sendMessage(javax.mail.Message message)
          Send message.
 void setAuthenticate(boolean authenticate)
          setAuthenticate
 void setCharSet(String charSet)
          setCharSet
 void setContentType(String contentType)
          setContentType
 void setDebug(boolean debug)
          setDebug
 void setEncoding(String encoding)
          setEncoding
 void setExtraHeaders(Map<String,String> headers)
           
 void setFileName(String fileName)
          setFileName
 void setFrom(String from)
          setFrom
 void setInputStream(InputStream inputStream)
          setInputStream
 void setInputStreamContentType(String inputStreamContentType)
          setInputStreamContentType
 void setInputStreamName(String inputStreamName)
          setInputStreamName
 void setMailer(String mailer)
          setMailer
 void setMailHost(String mail_host)
          setMailHost
 void setMessageText(String messageText)
          setMessageText
 void setPassword(String password)
          setPassword
 void setQuitWait(boolean quitWait)
          setQuitWait
 void setSession(javax.mail.Session session)
          setSession
 void setSmtpPort(int smtpPort)
          setSmtpPort
 void setSmtpSsl(boolean smtpSsl)
          setSmtpSsl
 void setStartTlsEnabled(boolean startTlsEnabled)
          setStartTlsEnabled
 void setSubject(String subject)
          setSubject
 void setTo(String to)
          setTo
 void setTransport(String transport)
          setTransport
 void setUseJMTA(boolean useMTA)
          setUseJMTA
 void setUser(String user)
          setUser
 
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

Constructor for JavaMailer.

Parameters:
javamailProps - a Properties object.
Throws:
JavaMailerException - if any.

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 - if any.
JavaMailerException - if any.
Method Detail

mailSend

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

Throws:
JavaMailerException - if any.

createAuthenticator

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

Returns:
a Authenticator object.

buildMessage

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

Returns:
completed message, ready to be passed to Transport.sendMessage
Throws:
JavaMailerException - if any of the underlying operations fail

createFileAttachment

public javax.mail.internet.MimeBodyPart createFileAttachment(File file)
                                                      throws javax.mail.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:
javax.mail.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(javax.mail.Message message)
                 throws JavaMailerException
Send message.

Parameters:
message - a Message object.
Throws:
JavaMailerException - if any.

getPassword

public String getPassword()

getPassword

Returns:
Returns the password.

setPassword

public void setPassword(String password)

setPassword

Parameters:
password - The password to set.

getUser

public String getUser()

getUser

Returns:
Returns the user.

setUser

public void setUser(String user)

setUser

Parameters:
user - The user to set.

isUseJMTA

public boolean isUseJMTA()

isUseJMTA

Returns:
Returns the _useMailHost.

setUseJMTA

public void setUseJMTA(boolean useMTA)

setUseJMTA

Parameters:
useMTA - a boolean.

getFrom

public String getFrom()

getFrom

Returns:
Returns the from address.

setFrom

public void setFrom(String from)

setFrom

Parameters:
from - The from address to set.

isAuthenticate

public boolean isAuthenticate()

isAuthenticate

Returns:
Returns the authenticate boolean.

setAuthenticate

public void setAuthenticate(boolean authenticate)

setAuthenticate

Parameters:
authenticate - The authenticate boolean to set.

getFileName

public String getFileName()

getFileName

Returns:
Returns the file name attachment.

setFileName

public void setFileName(String fileName)

setFileName

Parameters:
fileName - a String object.

getInputStream

public InputStream getInputStream()

getInputStream

Returns:
Returns the input stream attachment.

setInputStream

public void setInputStream(InputStream inputStream)

setInputStream

Parameters:
inputStream - Sets the input stream to be attached to the message.

getInputStreamName

public String getInputStreamName()

getInputStreamName

Returns:
Returns the name to use for stream attachments..

setInputStreamName

public void setInputStreamName(String inputStreamName)

setInputStreamName

Parameters:
inputStreamName - Sets the name to use for stream attachments.

getInputStreamContentType

public String getInputStreamContentType()

getInputStreamContentType

Returns:
Returns the name to use for stream attachments..

setInputStreamContentType

public void setInputStreamContentType(String inputStreamContentType)

setInputStreamContentType

Parameters:
inputStreamContentType - a String object.

getMailHost

public String getMailHost()

getMailHost

Returns:
Returns the mail host.

setMailHost

public void setMailHost(String mail_host)

setMailHost

Parameters:
mail_host - Sets the mail host.

getMailer

public String getMailer()

getMailer

Returns:
Returns the mailer.

setMailer

public void setMailer(String mailer)

setMailer

Parameters:
mailer - Sets the mailer.

getMessageText

public String getMessageText()

getMessageText

Returns:
Returns the message text.

setMessageText

public void setMessageText(String messageText)

setMessageText

Parameters:
messageText - Sets the message text.

getSubject

public String getSubject()

getSubject

Returns:
Returns the message Subject.

setSubject

public void setSubject(String subject)

setSubject

Parameters:
subject - Sets the message Subject.

getTo

public String getTo()

getTo

Returns:
Returns the To address.

setTo

public void setTo(String to)

setTo

Parameters:
to - Sets the To address.

getTransport

public String getTransport()

getTransport

Returns:
a String object.

setTransport

public void setTransport(String transport)

setTransport

Parameters:
transport - a String object.

isDebug

public boolean isDebug()

isDebug

Returns:
a boolean.

setDebug

public void setDebug(boolean debug)

setDebug

Parameters:
debug - a boolean.

getSession

public javax.mail.Session getSession()

getSession

Returns:
the session

setSession

public void setSession(javax.mail.Session session)

setSession

Parameters:
session - the session to set

getContentType

public String getContentType()

getContentType

Returns:
the contentType

setContentType

public void setContentType(String contentType)

setContentType

Parameters:
contentType - the contentType to set

getCharSet

public String getCharSet()

getCharSet

Returns:
the charSet

setCharSet

public void setCharSet(String charSet)

setCharSet

Parameters:
charSet - the charSet to set

getEncoding

public String getEncoding()

getEncoding

Returns:
the encoding

setEncoding

public void setEncoding(String encoding)

setEncoding

Parameters:
encoding - the encoding to set

isStartTlsEnabled

public boolean isStartTlsEnabled()

isStartTlsEnabled

Returns:
the startTlsEnabled

setStartTlsEnabled

public void setStartTlsEnabled(boolean startTlsEnabled)

setStartTlsEnabled

Parameters:
startTlsEnabled - the startTlsEnabled to set

isQuitWait

public boolean isQuitWait()

isQuitWait

Returns:
the quitWait

setQuitWait

public void setQuitWait(boolean quitWait)

setQuitWait

Parameters:
quitWait - the quitWait to set

getSmtpPort

public int getSmtpPort()

getSmtpPort

Returns:
the smtpPort

setSmtpPort

public void setSmtpPort(int smtpPort)

setSmtpPort

Parameters:
smtpPort - the smtpPort to set

isSmtpSsl

public boolean isSmtpSsl()

isSmtpSsl

Returns:
the smtpSsl

setSmtpSsl

public void setSmtpSsl(boolean smtpSsl)

setSmtpSsl

Parameters:
smtpSsl - the smtpSsl to set

getMailProps

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

Returns:
a Properties object.

getExtraHeaders

public Map<String,String> getExtraHeaders()

setExtraHeaders

public void setExtraHeaders(Map<String,String> headers)

addExtraHeader

public void addExtraHeader(String key,
                           String value)


Copyright © 2011. All Rights Reserved.