public class Emailer
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
Emailer.SMTPAuthenticator
SimpleAuthenticator is used to do simple authentication when the SMTP server requires it.
|
Modifier and Type | Field and Description |
---|---|
protected static org.apache.commons.logging.Log |
log
the log
|
Constructor and Description |
---|
Emailer(EmailConfig emailConfig)
Constructor
|
Emailer(KKEngIf eng)
Constructor
|
Modifier and Type | Method and Description |
---|---|
protected int |
createSmtpPortInt(java.lang.String smtpPort) |
protected java.lang.String |
emailConfigurationToString() |
java.lang.String |
getAttachmentFriendlyName() |
java.lang.String |
getAttachmentFullFilename() |
java.lang.String |
getBccEmails() |
java.lang.String |
getCcEmails() |
ConfigurationMgr |
getConfigMgr() |
java.lang.String |
getContentHTML() |
java.lang.String |
getContentText() |
static int |
getContentTypeOfTemplate(java.lang.String subjectAndBody,
java.lang.String templateFileName)
Try to determine the contentType of the template.
|
java.lang.String |
getDefaultBccEmails() |
protected EmailIntegrationMgrInterface |
getEmailIntegrationMgr()
Used to get an instance of the EmailIntegrationMgr
|
javax.mail.Address |
getFromAddress() |
javax.mail.Address |
getReplyToAddress() |
java.lang.String |
getSmtpPassword() |
java.lang.String |
getSmtpUsername() |
java.lang.String |
getSubject() |
static EmailTemplate |
getSubjectAndBody(java.lang.String subjectAndBody,
java.lang.String templateFileName,
int contentType)
Extract the subject and body from the supplied String that should contain the subject and the
body.
|
java.lang.String |
getToEmails() |
boolean |
isDeleteAttachmentFileAfterSend() |
boolean |
isDoBlindCopy() |
static boolean |
isEmailValid(java.lang.String emailAddr)
Determines whether the eMail address is valid
|
boolean |
isStartTLS() |
void |
refreshConfigs()
Setup variables needed to send the mail
|
protected void |
send()
Send an email message that has been fully defined before this call.
|
void |
sendHTML(EmailOptionsIf options)
Send a HTML-only email message to the specified recipient, with the specified subject, HTML
content and attachment options.
|
void |
sendHTML(java.lang.String toAddressString,
java.lang.String theSubject,
java.lang.String theContentHTML,
boolean blindCopy,
java.lang.String bccEmails,
boolean async)
Send a HTML-only email message to the specified recipient, with the specified subject and
HTML content.
|
void |
sendHTML(java.lang.String toAddressString,
java.lang.String theSubject,
java.lang.String theContentHTML,
boolean blindCopy,
java.lang.String fullAttachmentFilename,
java.lang.String friendlyAttachmentName,
boolean delAttachmentAfterSend,
java.lang.String bccEmails,
boolean async)
Send a HTML-only email message to the specified recipient, with the specified subject, HTML
content and attachment options.
|
void |
sendHTML(java.lang.String toAddressString,
java.lang.String fromAddressString,
java.lang.String theSubject,
java.lang.String theContentHTML,
boolean blindCopy,
java.lang.String bccEmails,
boolean async)
Send a HTML-only email message to the specified recipient, with the specified subject and
HTML content.
|
void |
sendHTML(java.lang.String toAddressString,
java.lang.String fromAddressString,
java.lang.String replyToAddressString,
java.lang.String theSubject,
java.lang.String theContentHTML,
boolean blindCopy,
java.lang.String bccEmails,
boolean async)
Send a HTML-only email message to the specified recipient, from the specified email address
with the specified subject and HTML content.
|
void |
sendMail(boolean async)
Send the mail either synchronously or asynchronously
|
void |
sendText(EmailOptionsIf options)
Send a Text email message to the specified recipient, with the specified subject, Text
content and attachment options.
|
void |
sendText(java.lang.String toAddressString,
java.lang.String theSubject,
java.lang.String theContentText,
boolean blindCopy,
java.lang.String bccEmails,
boolean async)
Send a text-only email message to the specified recipient, with the specified subject and
text content.
|
void |
sendText(java.lang.String toAddressString,
java.lang.String theSubject,
java.lang.String theContentText,
boolean blindCopy,
java.lang.String fullAttachmentFilename,
java.lang.String friendlyAttachmentName,
boolean delAttachmentAfterSend,
java.lang.String bccEmails,
boolean async)
Send a text-only email message to the specified recipient, with the specified subject, text
content and attachment options.
|
void |
sendText(java.lang.String toAddressString,
java.lang.String fromAddr,
java.lang.String theSubject,
java.lang.String theContentText,
boolean blindCopy,
java.lang.String bccEmails,
boolean async)
Send a text-only email message to the specified recipient, with the specified subject and
text content.
|
void |
sendText(java.lang.String toAddressString,
java.lang.String fromAddr,
java.lang.String replyToAddr,
java.lang.String theSubject,
java.lang.String theContentText,
boolean blindCopy,
java.lang.String bccEmails,
boolean async)
Send a text-only email message to the specified recipient, with the specified fromAddress,
replyToAddress, subject and text content.
|
void |
setAttachmentFriendlyName(java.lang.String attachmentFriendlyName) |
void |
setAttachmentFullFilename(java.lang.String attachmentFullFilename) |
void |
setBccEmails(java.lang.String bccEmails) |
void |
setCcEmails(java.lang.String ccEmails) |
void |
setContentHTML(java.lang.String contentHTML) |
void |
setContentText(java.lang.String contentText) |
void |
setDefaultBccEmails(java.lang.String defaultBccEmails) |
void |
setDeleteAttachmentFileAfterSend(boolean deleteAttachmentFileAfterSend) |
void |
setDoBlindCopy(boolean doBlindCopy) |
void |
setFromAddress(javax.mail.Address fromAddress) |
void |
setFromAddressFromString(java.lang.String fromAddressStr) |
void |
setReplyToAddress(javax.mail.Address replyToAddress) |
void |
setReplyToAddressFromString(java.lang.String replyToAddressStr) |
void |
setStartTLS(boolean startTLS) |
void |
setSubject(java.lang.String subject) |
void |
setToAddressFromString(java.lang.String toAddressString)
This is for backwards compatibility.
|
void |
setToEmails(java.lang.String toEmails) |
java.lang.String |
toString() |
public Emailer(KKEngIf eng) throws java.lang.Exception
eng
- the engjava.lang.Exception
- an unexpected exceptionpublic Emailer(EmailConfig emailConfig) throws java.lang.Exception
emailConfig
- Object containing configuration parametersjava.lang.Exception
- an unexpected exceptionpublic java.lang.String toString()
toString
in class java.lang.Object
public void refreshConfigs() throws java.lang.Exception
java.lang.Exception
- an unexpected exceptionprotected int createSmtpPortInt(java.lang.String smtpPort)
public void sendHTML(java.lang.String toAddressString, java.lang.String theSubject, java.lang.String theContentHTML, boolean blindCopy, java.lang.String bccEmails, boolean async) throws com.konakart.app.KKException
toAddressString
- the toAddressStringtheSubject
- the theSubjecttheContentHTML
- the theContentHTMLblindCopy
- the blindCopybccEmails
- the bccEmailsasync
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendHTML(java.lang.String toAddressString, java.lang.String fromAddressString, java.lang.String theSubject, java.lang.String theContentHTML, boolean blindCopy, java.lang.String bccEmails, boolean async) throws com.konakart.app.KKException
toAddressString
- the toAddressStringfromAddressString
- the fromAddressStringtheSubject
- the theSubjecttheContentHTML
- the theContentHTMLblindCopy
- the blindCopybccEmails
- the bccEmailsasync
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendHTML(java.lang.String toAddressString, java.lang.String fromAddressString, java.lang.String replyToAddressString, java.lang.String theSubject, java.lang.String theContentHTML, boolean blindCopy, java.lang.String bccEmails, boolean async) throws com.konakart.app.KKException
toAddressString
- the toAddressStringfromAddressString
- the fromAddressStringreplyToAddressString
- the replyToAddressStringtheSubject
- the theSubjecttheContentHTML
- the theContentHTMLblindCopy
- the blindCopybccEmails
- the bccEmailsasync
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendHTML(java.lang.String toAddressString, java.lang.String theSubject, java.lang.String theContentHTML, boolean blindCopy, java.lang.String fullAttachmentFilename, java.lang.String friendlyAttachmentName, boolean delAttachmentAfterSend, java.lang.String bccEmails, boolean async) throws com.konakart.app.KKException
toAddressString
- the toAddressStringtheSubject
- the theSubjecttheContentHTML
- the theContentHTMLblindCopy
- the blindCopyfullAttachmentFilename
- full filename of the attachmentfriendlyAttachmentName
- friendly name to use for the attachmentdelAttachmentAfterSend
- set to true to delete the attachment file after the sendbccEmails
- the bccEmailsasync
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendHTML(EmailOptionsIf options) throws com.konakart.app.KKException
options
- the EmailOptionsIf objectcom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendText(java.lang.String toAddressString, java.lang.String fromAddr, java.lang.String theSubject, java.lang.String theContentText, boolean blindCopy, java.lang.String bccEmails, boolean async) throws com.konakart.app.KKException
toAddressString
- the toAddressStringfromAddr
- the fromAddrtheSubject
- the theSubjecttheContentText
- the theContentTextblindCopy
- the blindCopybccEmails
- the bccEmailsasync
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendText(java.lang.String toAddressString, java.lang.String theSubject, java.lang.String theContentText, boolean blindCopy, java.lang.String bccEmails, boolean async) throws com.konakart.app.KKException
toAddressString
- the toAddressStringtheSubject
- the theSubjecttheContentText
- the theContentTextblindCopy
- the blindCopybccEmails
- the bccEmailsasync
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendText(java.lang.String toAddressString, java.lang.String fromAddr, java.lang.String replyToAddr, java.lang.String theSubject, java.lang.String theContentText, boolean blindCopy, java.lang.String bccEmails, boolean async) throws com.konakart.app.KKException
toAddressString
- the toAddressStringfromAddr
- the fromAddrreplyToAddr
- the replyToAddrtheSubject
- the theSubjecttheContentText
- the theContentTextblindCopy
- the blindCopybccEmails
- the bccEmailsasync
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendText(java.lang.String toAddressString, java.lang.String theSubject, java.lang.String theContentText, boolean blindCopy, java.lang.String fullAttachmentFilename, java.lang.String friendlyAttachmentName, boolean delAttachmentAfterSend, java.lang.String bccEmails, boolean async) throws com.konakart.app.KKException
toAddressString
- the toAddressStringtheSubject
- the theSubjecttheContentText
- the theContentTextblindCopy
- the blindCopyfullAttachmentFilename
- full filename of the attachmentfriendlyAttachmentName
- friendly name to use for the attachmentdelAttachmentAfterSend
- set to true to delete the attachment file after the sendbccEmails
- the bccEmailsasync
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendText(EmailOptionsIf options) throws com.konakart.app.KKException
options
- the EmailOptionsIf objectcom.konakart.app.KKException
- an unexpected KKException exceptionpublic void sendMail(boolean async) throws com.konakart.app.KKException
async
- the asynccom.konakart.app.KKException
- an unexpected KKException exceptionprotected void send() throws com.konakart.app.KKException
com.konakart.app.KKException
- an unexpected KKException exceptionprotected java.lang.String emailConfigurationToString()
public ConfigurationMgr getConfigMgr() throws java.lang.Exception
java.lang.Exception
- an unexpected exceptionpublic static boolean isEmailValid(java.lang.String emailAddr)
emailAddr
- the emailAddrprotected EmailIntegrationMgrInterface getEmailIntegrationMgr() throws org.apache.torque.TorqueException, com.konakart.app.KKException, com.workingdogs.village.DataSetException, java.lang.Exception
java.lang.Exception
- an unexpected exceptioncom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)com.konakart.app.KKException
- an unexpected KKException exceptionorg.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)public static EmailTemplate getSubjectAndBody(java.lang.String subjectAndBody, java.lang.String templateFileName, int contentType) throws com.konakart.app.KKException
The extracted items are returned in the EmailTemplate object.
subjectAndBody
- the subjectAndBodytemplateFileName
- supplied only to provide context information in error messages and exceptionscontentType
- the contentTypecom.konakart.app.KKException
- an unexpected KKException exceptionpublic static int getContentTypeOfTemplate(java.lang.String subjectAndBody, java.lang.String templateFileName) throws com.konakart.app.KKException
The logic is fairly crude; if we find HTML or DOCTYPE tags we assume it's HTML, otherwise plain text.
subjectAndBody
- the subjectAndBodytemplateFileName
- supplied only to provide context information in error messages and exceptionscom.konakart.app.KKException
- an unexpected KKException exceptionpublic java.lang.String getSubject()
public java.lang.String getSmtpUsername()
public java.lang.String getSmtpPassword()
public javax.mail.Address getFromAddress()
public void setFromAddress(javax.mail.Address fromAddress)
fromAddress
- the fromAddress to setpublic void setFromAddressFromString(java.lang.String fromAddressStr) throws com.konakart.app.KKException
fromAddressStr
- the fromAddress to setcom.konakart.app.KKException
- an unexpected KKException exceptionpublic javax.mail.Address getReplyToAddress()
public void setReplyToAddress(javax.mail.Address replyToAddress)
replyToAddress
- the replyToAddress to setpublic void setReplyToAddressFromString(java.lang.String replyToAddressStr) throws com.konakart.app.KKException
replyToAddressStr
- the replyToAddress to setcom.konakart.app.KKException
- an unexpected KKException exceptionpublic void setSubject(java.lang.String subject)
subject
- the subject to setpublic java.lang.String getBccEmails()
public void setBccEmails(java.lang.String bccEmails)
bccEmails
- the bccEmails to setpublic java.lang.String getContentText()
public void setContentText(java.lang.String contentText)
contentText
- the contentText to setpublic java.lang.String getContentHTML()
public void setContentHTML(java.lang.String contentHTML)
contentHTML
- the contentHTML to setpublic java.lang.String getAttachmentFullFilename()
public void setAttachmentFullFilename(java.lang.String attachmentFullFilename)
attachmentFullFilename
- the attachmentFullFilename to setpublic java.lang.String getAttachmentFriendlyName()
public void setAttachmentFriendlyName(java.lang.String attachmentFriendlyName)
attachmentFriendlyName
- the attachmentFriendlyName to setpublic boolean isDeleteAttachmentFileAfterSend()
public void setDeleteAttachmentFileAfterSend(boolean deleteAttachmentFileAfterSend)
deleteAttachmentFileAfterSend
- the deleteAttachmentFileAfterSend to setpublic boolean isDoBlindCopy()
public void setDoBlindCopy(boolean doBlindCopy)
doBlindCopy
- the doBlindCopy to setpublic java.lang.String getCcEmails()
public void setCcEmails(java.lang.String ccEmails)
ccEmails
- the ccEmails to setpublic java.lang.String getToEmails()
public void setToEmails(java.lang.String toEmails)
toEmails
- the toEmails to setpublic void setToAddressFromString(java.lang.String toAddressString)
toAddressString
- the to addresspublic java.lang.String getDefaultBccEmails()
public void setDefaultBccEmails(java.lang.String defaultBccEmails)
defaultBccEmails
- the defaultBccEmails to setpublic boolean isStartTLS()
public void setStartTLS(boolean startTLS)
startTLS
- the startTLS to setCopyright © 2018 DS Data Systems UK Ltd.