Package org.opennms.javamail
Class JavaMailer
- java.lang.Object
-
- org.opennms.javamail.JavaMailer
-
public class JavaMailer extends java.lang.ObjectSends an email message using the Java Mail API- Version:
- $Id: $
- Author:
- David Hustace
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJavaMailer.LoggingByteArrayOutputStreamstatic classJavaMailer.LoggingTransportListener
-
Constructor Summary
Constructors Constructor Description JavaMailer()Default constructor.JavaMailer(java.util.Properties javamailProps)Constructor for JavaMailer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExtraHeader(java.lang.String key, java.lang.String value)javax.mail.MessagebuildMessage()Build a complete message ready for sending.javax.mail.AuthenticatorcreateAuthenticator()Helper method to create an Authenticator based on Password Authenticationjavax.mail.internet.MimeBodyPartcreateFileAttachment(java.io.File file)Create a file attachment as a MimeBodyPart, checking to see if the file exists before we create the attachment.java.lang.StringgetCharSet()getCharSetjava.lang.StringgetContentType()getContentTypejava.lang.StringgetEncoding()getEncodingjava.util.Map<java.lang.String,java.lang.String>getExtraHeaders()java.lang.StringgetFileName()getFileNamejava.lang.StringgetFrom()getFromjava.io.InputStreamgetInputStream()getInputStreamjava.lang.StringgetInputStreamContentType()getInputStreamContentTypejava.lang.StringgetInputStreamName()getInputStreamNamejava.lang.StringgetMailer()getMailerjava.lang.StringgetMailHost()getMailHostjava.util.PropertiesgetMailProps()This returns the properties configured in the javamail-configuration.properties file.java.lang.StringgetMessageText()getMessageTextjava.lang.StringgetPassword()getPasswordjava.lang.StringgetReplyTo()getReplyTojavax.mail.SessiongetSession()getSessionintgetSmtpPort()getSmtpPortjava.lang.StringgetSubject()getSubjectjava.lang.StringgetTo()getTojava.lang.StringgetTransport()getTransportjava.lang.StringgetUser()getUserbooleanisAuthenticate()isAuthenticatebooleanisDebug()isDebugbooleanisQuitWait()isQuitWaitbooleanisSmtpSsl()isSmtpSslbooleanisStartTlsEnabled()isStartTlsEnabledbooleanisUseJMTA()isUseJMTAvoidmailSend()Sends a message based on properties set on this bean.voidsendMessage(javax.mail.Message message)Send message.voidsetAuthenticate(boolean authenticate)setAuthenticatevoidsetCharSet(java.lang.String charSet)setCharSetvoidsetContentType(java.lang.String contentType)setContentTypevoidsetDebug(boolean debug)setDebugvoidsetEncoding(java.lang.String encoding)setEncodingvoidsetExtraHeaders(java.util.Map<java.lang.String,java.lang.String> headers)voidsetFileName(java.lang.String fileName)setFileNamevoidsetFrom(java.lang.String from)setFromvoidsetInputStream(java.io.InputStream inputStream)setInputStreamvoidsetInputStreamContentType(java.lang.String inputStreamContentType)setInputStreamContentTypevoidsetInputStreamName(java.lang.String inputStreamName)setInputStreamNamevoidsetMailer(java.lang.String mailer)setMailervoidsetMailHost(java.lang.String mail_host)setMailHostvoidsetMessageText(java.lang.String messageText)setMessageTextvoidsetPassword(java.lang.String password)setPasswordvoidsetQuitWait(boolean quitWait)setQuitWaitvoidsetSession(javax.mail.Session session)setSessionvoidsetSmtpPort(int smtpPort)setSmtpPortvoidsetSmtpSsl(boolean smtpSsl)setSmtpSslvoidsetStartTlsEnabled(boolean startTlsEnabled)setStartTlsEnabledvoidsetSubject(java.lang.String subject)setSubjectvoidsetTo(java.lang.String to)setTovoidsetTransport(java.lang.String transport)setTransportvoidsetUseJMTA(boolean useMTA)setUseJMTAvoidsetUser(java.lang.String user)setUser
-
-
-
Constructor Detail
-
JavaMailer
public JavaMailer(java.util.Properties javamailProps) throws JavaMailerExceptionConstructor for JavaMailer.
- Parameters:
javamailProps- aPropertiesobject.- Throws:
JavaMailerException- if any.
-
JavaMailer
public JavaMailer() throws JavaMailerExceptionDefault 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:
java.io.IOException- if any.JavaMailerException- if any.
-
-
Method Detail
-
mailSend
public void mailSend() throws JavaMailerExceptionSends 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
Authenticatorobject.
-
buildMessage
public javax.mail.Message buildMessage() throws JavaMailerExceptionBuild 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(java.io.File file) throws javax.mail.MessagingException, JavaMailerExceptionCreate 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 MimeBodyPartJavaMailerException- if the file does not exist or is not readable
-
sendMessage
public void sendMessage(javax.mail.Message message) throws JavaMailerExceptionSend message.- Parameters:
message- aMessageobject.- Throws:
JavaMailerException- if any.
-
getPassword
public java.lang.String getPassword()
getPassword
- Returns:
- Returns the password.
-
setPassword
public void setPassword(java.lang.String password)
setPassword
- Parameters:
password- The password to set.
-
getUser
public java.lang.String getUser()
getUser
- Returns:
- Returns the user.
-
setUser
public void setUser(java.lang.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 java.lang.String getFrom()
getFrom
- Returns:
- Returns the from address.
-
getReplyTo
public java.lang.String getReplyTo()
getReplyTo
- Returns:
- Returns the replyTo address.
-
setFrom
public void setFrom(java.lang.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 java.lang.String getFileName()
getFileName
- Returns:
- Returns the file name attachment.
-
setFileName
public void setFileName(java.lang.String fileName)
setFileName
- Parameters:
fileName- aStringobject.
-
getInputStream
public java.io.InputStream getInputStream()
getInputStream
- Returns:
- Returns the input stream attachment.
-
setInputStream
public void setInputStream(java.io.InputStream inputStream)
setInputStream
- Parameters:
inputStream- Sets the input stream to be attached to the message.
-
getInputStreamName
public java.lang.String getInputStreamName()
getInputStreamName
- Returns:
- Returns the name to use for stream attachments..
-
setInputStreamName
public void setInputStreamName(java.lang.String inputStreamName)
setInputStreamName
- Parameters:
inputStreamName- Sets the name to use for stream attachments.
-
getInputStreamContentType
public java.lang.String getInputStreamContentType()
getInputStreamContentType
- Returns:
- Returns the name to use for stream attachments..
-
setInputStreamContentType
public void setInputStreamContentType(java.lang.String inputStreamContentType)
setInputStreamContentType
- Parameters:
inputStreamContentType- aStringobject.
-
getMailHost
public java.lang.String getMailHost()
getMailHost
- Returns:
- Returns the mail host.
-
setMailHost
public void setMailHost(java.lang.String mail_host)
setMailHost
- Parameters:
mail_host- Sets the mail host.
-
getMailer
public java.lang.String getMailer()
getMailer
- Returns:
- Returns the mailer.
-
setMailer
public void setMailer(java.lang.String mailer)
setMailer
- Parameters:
mailer- Sets the mailer.
-
getMessageText
public java.lang.String getMessageText()
getMessageText
- Returns:
- Returns the message text.
-
setMessageText
public void setMessageText(java.lang.String messageText)
setMessageText
- Parameters:
messageText- Sets the message text.
-
getSubject
public java.lang.String getSubject()
getSubject
- Returns:
- Returns the message Subject.
-
setSubject
public void setSubject(java.lang.String subject)
setSubject
- Parameters:
subject- Sets the message Subject.
-
getTo
public java.lang.String getTo()
getTo
- Returns:
- Returns the To address.
-
setTo
public void setTo(java.lang.String to)
setTo
- Parameters:
to- Sets the To address.
-
getTransport
public java.lang.String getTransport()
getTransport
- Returns:
- a
Stringobject.
-
setTransport
public void setTransport(java.lang.String transport)
setTransport
- Parameters:
transport- aStringobject.
-
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 java.lang.String getContentType()
getContentType
- Returns:
- the contentType
-
setContentType
public void setContentType(java.lang.String contentType)
setContentType
- Parameters:
contentType- the contentType to set
-
getCharSet
public java.lang.String getCharSet()
getCharSet
- Returns:
- the charSet
-
setCharSet
public void setCharSet(java.lang.String charSet)
setCharSet
- Parameters:
charSet- the charSet to set
-
getEncoding
public java.lang.String getEncoding()
getEncoding
- Returns:
- the encoding
-
setEncoding
public void setEncoding(java.lang.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 java.util.Properties getMailProps()
This returns the properties configured in the javamail-configuration.properties file.- Returns:
- a
Propertiesobject.
-
getExtraHeaders
public java.util.Map<java.lang.String,java.lang.String> getExtraHeaders()
-
setExtraHeaders
public void setExtraHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
-
addExtraHeader
public void addExtraHeader(java.lang.String key, java.lang.String value)
-
-