From 95ba68960ebef5c138010e6f52ed0c5a7d40c72e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 18 May 2016 15:37:42 +0200 Subject: [PATCH] added method init() --- .../jmailee/model/delivery/BaseMailer.java | 43 ++++++++++++++++--- .../model/delivery/DeliverableEmail.java | 9 ++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/org/mxchange/jmailee/model/delivery/BaseMailer.java b/src/org/mxchange/jmailee/model/delivery/BaseMailer.java index 361ce5d..851205d 100644 --- a/src/org/mxchange/jmailee/model/delivery/BaseMailer.java +++ b/src/org/mxchange/jmailee/model/delivery/BaseMailer.java @@ -59,10 +59,10 @@ public abstract class BaseMailer implements DeliverableEmail { /** * Properties for this mailer *

- * Valid are: - mailer.errorsto = Email address for "Errors-To" header - - * mailer.bouncesto = Email address for "Bounces-To" header (optional, if - * not set, errorsto must be set) - mailer.xloop = Email address for - * "X-Loop" header (optional, if not set, errorsto must be set) + * Valid are: + * - mailer.errorsto = Email address for "Errors-To" header + * - mailer.bouncesto = Email address for "Bounces-To" header (optional, if not set, errorsto must be set) + * - mailer.xloop = Email address for "X-Loop" header (optional, if not set, errorsto must be set) */ private Properties properties; @@ -98,6 +98,30 @@ public abstract class BaseMailer implements DeliverableEmail { return this.templateEngine; } + @Override + public void init (final Properties properties) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("init: properties={0} - CALLED!", properties)); //NOI18N + + // Are all required properties set? + if (null == properties) { + // Is null + throw new NullPointerException("properties is null"); //NOI18N + } else if (!properties.containsKey("mailer.errorsto")) { //NOI18N + // Errors-To not set + throw new IllegalArgumentException("properties.mailer.errorsto is not set"); //NOI18N + } else if (!properties.containsKey("mailer.bouncesto")) { //NOI18N + // Errors-To not set + throw new IllegalArgumentException("properties.mailer.bouncesto is not set"); //NOI18N + } + + // Set it here + this.properties = properties; + + // Trace message + this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N + } + /** * Sends an email to given email address with subject line. *

@@ -109,6 +133,15 @@ public abstract class BaseMailer implements DeliverableEmail { * @throws MessagingException If something happened on message delivery */ private void sendMail (final Address emailAddress, final String subjectLine, final String body, final Session mailSession) throws MessagingException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendMail: emailAddress={0},subjectLine={1},body={2},mailSession={3} - CALLED!", emailAddress, subjectLine, body, mailSession)); //NOI18N + + // Are the additional properties set? + if (null == this.properties) { + // Nothing set + throw new NullPointerException("this.properties is null"); //NOI18N + } + // Get MIME message instance MimeMessage message = new MimeMessage(mailSession); @@ -189,7 +222,7 @@ public abstract class BaseMailer implements DeliverableEmail { } else if (emailWrapper.getTemplateName().isEmpty()) { // Is empty throw new IllegalArgumentException("emailWrapper.templateName is empty"); //NOI18N - } else if (emailWrapper.getLocale()== null) { + } else if (emailWrapper.getLocale() == null) { // Throw NPE again throw new NullPointerException("emailWrapper.locale is null"); //NOI18N } diff --git a/src/org/mxchange/jmailee/model/delivery/DeliverableEmail.java b/src/org/mxchange/jmailee/model/delivery/DeliverableEmail.java index 6c83433..895dda8 100644 --- a/src/org/mxchange/jmailee/model/delivery/DeliverableEmail.java +++ b/src/org/mxchange/jmailee/model/delivery/DeliverableEmail.java @@ -17,6 +17,7 @@ package org.mxchange.jmailee.model.delivery; import java.io.Serializable; +import java.util.Properties; import org.apache.velocity.app.VelocityEngine; /** @@ -33,4 +34,12 @@ public interface DeliverableEmail extends Serializable { */ VelocityEngine getTemplateEngine (); + /** + * Initializes the mailer with given properties. Please see BaseMailer for + * all supported and required properties. + *

+ * @param properties Properties instance + */ + void init (final Properties properties); + } -- 2.39.2