Package org.europa.together.application
Class JavaMailClient
- java.lang.Object
-
- org.europa.together.application.JavaMailClient
-
- All Implemented Interfaces:
MailClient
@Repository @FeatureToggle(featureID="CM-0006") public class JavaMailClient extends Object implements MailClient
Implementation of a simple SMTP Mailer.
-
-
Field Summary
-
Fields inherited from interface org.europa.together.business.MailClient
CONFIG_SET, CONFIG_VERSION, FEATURE_ID
-
-
Constructor Summary
Constructors Constructor Description JavaMailClient()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddAttachment(String resource)Add an attachment to the Attachment List.voidaddAttachmentList(List<String> attachmentList)Add attachments from a given List of strings to the mail attachments.booleanaddRecipent(String recipient)Add an Recipient to the Recipient List.voidaddRecipientList(List<String> recipientList)Add a recipient from a given list of Strings to the mail recipients.voidclearAttachments()Reset the Attachment List.voidclearConfiguration()Clean (reset) the mailer configuration.voidclearRecipents()Reset the Recipient List.javax.mail.internet.MimeMessagecomposeMail(javax.mail.internet.InternetAddress recipient)Compose a full E-Mail, ready to send.List<javax.activation.FileDataSource>getAttachmentList()longgetAttachmentSize()intgetBulkMailLimiter()Get the limitation of the maximum amount of sending e-mails until a time interrupt will be processed.Map<String,String>getConfiguration()Get the full SMTP Configuration.StringgetContent()StringgetMimeType()List<javax.mail.internet.InternetAddress>getRecipentList()javax.mail.SessiongetSession()Get the configured session to connect the SMTP Server.StringgetSubject()longgetWaitTime()Get the Configured wait time in milliseconds until the next mail bulk can be send.booleanloadConfigurationFromDatabase()booleanloadConfigurationFromProperties(String resource)voidpopulateDbConfiguration(String sqlFile, boolean... connectTestDb)Population the database with the MailClient Configuration.voidsetAttachmentSize(long attachmentSize)Limit the maximum file size for attachments.voidsetContent(String content)Add E-MAil content from a String.voidsetMimeTypeToHTML()Set the MimeType of a E-Mail to HTML.voidsetMimeTypeToPlain()Set the MimeType of an E-Mail to plain text.voidsetSubject(String subject)Add a subject (topic) to the mail.
-
-
-
Method Detail
-
addAttachmentList
public void addAttachmentList(List<String> attachmentList)
Description copied from interface:MailClientAdd attachments from a given List of strings to the mail attachments. A list entry represents the full path to the attachment as String.- Specified by:
addAttachmentListin interfaceMailClient- Parameters:
attachmentList- as String
-
addRecipientList
public void addRecipientList(List<String> recipientList)
Description copied from interface:MailClientAdd a recipient from a given list of Strings to the mail recipients. A list entry represent a E-Mail Address as String. This function allows an import e-mail from other systems.- Specified by:
addRecipientListin interfaceMailClient- Parameters:
recipientList- as String
-
clearAttachments
public void clearAttachments()
Description copied from interface:MailClientReset the Attachment List.- Specified by:
clearAttachmentsin interfaceMailClient
-
clearRecipents
public void clearRecipents()
Description copied from interface:MailClientReset the Recipient List.- Specified by:
clearRecipentsin interfaceMailClient
-
populateDbConfiguration
public void populateDbConfiguration(String sqlFile, boolean... connectTestDb)
Description copied from interface:MailClientPopulation the database with the MailClient Configuration.- Specified by:
populateDbConfigurationin interfaceMailClient- Parameters:
sqlFile- as StringconnectTestDb- as boolean
-
setAttachmentSize
public void setAttachmentSize(long attachmentSize)
Description copied from interface:MailClientLimit the maximum file size for attachments.- Specified by:
setAttachmentSizein interfaceMailClient- Parameters:
attachmentSize- as long
-
setContent
public void setContent(String content)
Description copied from interface:MailClientAdd E-MAil content from a String.- Specified by:
setContentin interfaceMailClient- Parameters:
content- as String
-
setMimeTypeToHTML
public void setMimeTypeToHTML()
Description copied from interface:MailClientSet the MimeType of a E-Mail to HTML.- Specified by:
setMimeTypeToHTMLin interfaceMailClient
-
setMimeTypeToPlain
public void setMimeTypeToPlain()
Description copied from interface:MailClientSet the MimeType of an E-Mail to plain text.- Specified by:
setMimeTypeToPlainin interfaceMailClient
-
setSubject
public void setSubject(String subject)
Description copied from interface:MailClientAdd a subject (topic) to the mail.- Specified by:
setSubjectin interfaceMailClient- Parameters:
subject- as String
-
addAttachment
public boolean addAttachment(String resource)
Description copied from interface:MailClientAdd an attachment to the Attachment List. The file size of attachments can be limited. To refer an attachment, set the resource e.g.: picture.png- Specified by:
addAttachmentin interfaceMailClient- Parameters:
resource- as String- Returns:
- true on success
-
addRecipent
public boolean addRecipent(String recipient)
Description copied from interface:MailClientAdd an Recipient to the Recipient List. The implementation check if the recipient already exist in the List. Also the format of an valid e-mail address will be tested. If an given E-Mail address is not valid it will not added to the List.- Specified by:
addRecipentin interfaceMailClient- Parameters:
recipient- as String- Returns:
- true on success
-
clearConfiguration
public void clearConfiguration()
Description copied from interface:MailClientClean (reset) the mailer configuration.- Specified by:
clearConfigurationin interfaceMailClient
-
loadConfigurationFromProperties
public boolean loadConfigurationFromProperties(String resource)
- Specified by:
loadConfigurationFromPropertiesin interfaceMailClient- Parameters:
resource- as String- Returns:
- true on success
-
loadConfigurationFromDatabase
public boolean loadConfigurationFromDatabase()
- Specified by:
loadConfigurationFromDatabasein interfaceMailClient- Returns:
- true on success
-
getBulkMailLimiter
public int getBulkMailLimiter()
Description copied from interface:MailClientGet the limitation of the maximum amount of sending e-mails until a time interrupt will be processed.- Specified by:
getBulkMailLimiterin interfaceMailClient- Returns:
- limitOfBulkMails as int
-
getAttachmentSize
public long getAttachmentSize()
- Specified by:
getAttachmentSizein interfaceMailClient- Returns:
- size as long
-
getWaitTime
public long getWaitTime()
Description copied from interface:MailClientGet the Configured wait time in milliseconds until the next mail bulk can be send.- Specified by:
getWaitTimein interfaceMailClient- Returns:
- waitTime as long
-
getSession
public javax.mail.Session getSession()
Description copied from interface:MailClientGet the configured session to connect the SMTP Server.- Specified by:
getSessionin interfaceMailClient- Returns:
- session as Session
-
getContent
public String getContent()
- Specified by:
getContentin interfaceMailClient- Returns:
- content as String
-
getMimeType
public String getMimeType()
- Specified by:
getMimeTypein interfaceMailClient- Returns:
- mimeType as String
-
getSubject
public String getSubject()
- Specified by:
getSubjectin interfaceMailClient- Returns:
- subject as String
-
getAttachmentList
public List<javax.activation.FileDataSource> getAttachmentList()
- Specified by:
getAttachmentListin interfaceMailClient- Returns:
- attachments as List
-
getRecipentList
public List<javax.mail.internet.InternetAddress> getRecipentList()
- Specified by:
getRecipentListin interfaceMailClient- Returns:
- recipients as List
-
getConfiguration
public Map<String,String> getConfiguration()
Description copied from interface:MailClientGet the full SMTP Configuration.- Specified by:
getConfigurationin interfaceMailClient- Returns:
- configuration as Map
-
composeMail
public javax.mail.internet.MimeMessage composeMail(javax.mail.internet.InternetAddress recipient) throws javax.mail.MessagingExceptionDescription copied from interface:MailClientCompose a full E-Mail, ready to send.- Specified by:
composeMailin interfaceMailClient- Parameters:
recipient- as InternetAddress- Returns:
- e-mail as MimeMessage
- Throws:
javax.mail.MessagingException- by error
-
-