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 boolean
addAttachment(String resource)
Add an attachment to the Attachment List.void
addAttachmentList(List<String> attachmentList)
Add attachments from a given List of strings to the mail attachments.boolean
addRecipent(String recipient)
Add an Recipient to the Recipient List.void
addRecipientList(List<String> recipientList)
Add a recipient from a given list of Strings to the mail recipients.void
clearAttachments()
Reset the Attachment List.void
clearConfiguration()
Clean (reset) the mailer configuration.void
clearRecipents()
Reset the Recipient List.javax.mail.internet.MimeMessage
composeMail(javax.mail.internet.InternetAddress recipient)
Compose a full E-Mail, ready to send.List<javax.activation.FileDataSource>
getAttachmentList()
long
getAttachmentSize()
int
getBulkMailLimiter()
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.String
getContent()
String
getMimeType()
List<javax.mail.internet.InternetAddress>
getRecipentList()
javax.mail.Session
getSession()
Get the configured session to connect the SMTP Server.String
getSubject()
long
getWaitTime()
Get the Configured wait time in milliseconds until the next mail bulk can be send.boolean
loadConfigurationFromDatabase()
boolean
loadConfigurationFromProperties(String resource)
void
populateDbConfiguration(String sqlFile, boolean... connectTestDb)
Population the database with the MailClient Configuration.void
setAttachmentSize(long attachmentSize)
Limit the maximum file size for attachments.void
setContent(String content)
Add E-MAil content from a String.void
setMimeTypeToHTML()
Set the MimeType of a E-Mail to HTML.void
setMimeTypeToPlain()
Set the MimeType of an E-Mail to plain text.void
setSubject(String subject)
Add a subject (topic) to the mail.
-
-
-
Method Detail
-
addAttachmentList
public void addAttachmentList(List<String> attachmentList)
Description copied from interface:MailClient
Add 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:
addAttachmentList
in interfaceMailClient
- Parameters:
attachmentList
- as String
-
addRecipientList
public void addRecipientList(List<String> recipientList)
Description copied from interface:MailClient
Add 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:
addRecipientList
in interfaceMailClient
- Parameters:
recipientList
- as String
-
clearAttachments
public void clearAttachments()
Description copied from interface:MailClient
Reset the Attachment List.- Specified by:
clearAttachments
in interfaceMailClient
-
clearRecipents
public void clearRecipents()
Description copied from interface:MailClient
Reset the Recipient List.- Specified by:
clearRecipents
in interfaceMailClient
-
populateDbConfiguration
public void populateDbConfiguration(String sqlFile, boolean... connectTestDb)
Description copied from interface:MailClient
Population the database with the MailClient Configuration.- Specified by:
populateDbConfiguration
in interfaceMailClient
- Parameters:
sqlFile
- as StringconnectTestDb
- as boolean
-
setAttachmentSize
public void setAttachmentSize(long attachmentSize)
Description copied from interface:MailClient
Limit the maximum file size for attachments.- Specified by:
setAttachmentSize
in interfaceMailClient
- Parameters:
attachmentSize
- as long
-
setContent
public void setContent(String content)
Description copied from interface:MailClient
Add E-MAil content from a String.- Specified by:
setContent
in interfaceMailClient
- Parameters:
content
- as String
-
setMimeTypeToHTML
public void setMimeTypeToHTML()
Description copied from interface:MailClient
Set the MimeType of a E-Mail to HTML.- Specified by:
setMimeTypeToHTML
in interfaceMailClient
-
setMimeTypeToPlain
public void setMimeTypeToPlain()
Description copied from interface:MailClient
Set the MimeType of an E-Mail to plain text.- Specified by:
setMimeTypeToPlain
in interfaceMailClient
-
setSubject
public void setSubject(String subject)
Description copied from interface:MailClient
Add a subject (topic) to the mail.- Specified by:
setSubject
in interfaceMailClient
- Parameters:
subject
- as String
-
addAttachment
public boolean addAttachment(String resource)
Description copied from interface:MailClient
Add 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:
addAttachment
in interfaceMailClient
- Parameters:
resource
- as String- Returns:
- true on success
-
addRecipent
public boolean addRecipent(String recipient)
Description copied from interface:MailClient
Add 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:
addRecipent
in interfaceMailClient
- Parameters:
recipient
- as String- Returns:
- true on success
-
clearConfiguration
public void clearConfiguration()
Description copied from interface:MailClient
Clean (reset) the mailer configuration.- Specified by:
clearConfiguration
in interfaceMailClient
-
loadConfigurationFromProperties
public boolean loadConfigurationFromProperties(String resource)
- Specified by:
loadConfigurationFromProperties
in interfaceMailClient
- Parameters:
resource
- as String- Returns:
- true on success
-
loadConfigurationFromDatabase
public boolean loadConfigurationFromDatabase()
- Specified by:
loadConfigurationFromDatabase
in interfaceMailClient
- Returns:
- true on success
-
getBulkMailLimiter
public int getBulkMailLimiter()
Description copied from interface:MailClient
Get the limitation of the maximum amount of sending e-mails until a time interrupt will be processed.- Specified by:
getBulkMailLimiter
in interfaceMailClient
- Returns:
- limitOfBulkMails as int
-
getAttachmentSize
public long getAttachmentSize()
- Specified by:
getAttachmentSize
in interfaceMailClient
- Returns:
- size as long
-
getWaitTime
public long getWaitTime()
Description copied from interface:MailClient
Get the Configured wait time in milliseconds until the next mail bulk can be send.- Specified by:
getWaitTime
in interfaceMailClient
- Returns:
- waitTime as long
-
getSession
public javax.mail.Session getSession()
Description copied from interface:MailClient
Get the configured session to connect the SMTP Server.- Specified by:
getSession
in interfaceMailClient
- Returns:
- session as Session
-
getContent
public String getContent()
- Specified by:
getContent
in interfaceMailClient
- Returns:
- content as String
-
getMimeType
public String getMimeType()
- Specified by:
getMimeType
in interfaceMailClient
- Returns:
- mimeType as String
-
getSubject
public String getSubject()
- Specified by:
getSubject
in interfaceMailClient
- Returns:
- subject as String
-
getAttachmentList
public List<javax.activation.FileDataSource> getAttachmentList()
- Specified by:
getAttachmentList
in interfaceMailClient
- Returns:
- attachments as List
-
getRecipentList
public List<javax.mail.internet.InternetAddress> getRecipentList()
- Specified by:
getRecipentList
in interfaceMailClient
- Returns:
- recipients as List
-
getConfiguration
public Map<String,String> getConfiguration()
Description copied from interface:MailClient
Get the full SMTP Configuration.- Specified by:
getConfiguration
in interfaceMailClient
- Returns:
- configuration as Map
-
composeMail
public javax.mail.internet.MimeMessage composeMail(javax.mail.internet.InternetAddress recipient) throws javax.mail.MessagingException
Description copied from interface:MailClient
Compose a full E-Mail, ready to send.- Specified by:
composeMail
in interfaceMailClient
- Parameters:
recipient
- as InternetAddress- Returns:
- e-mail as MimeMessage
- Throws:
javax.mail.MessagingException
- by error
-
-