]> git.mxchange.org Git - jmailer-ee.git/commitdiff
added method init()
authorRoland Häder <roland@mxchange.org>
Wed, 18 May 2016 13:37:42 +0000 (15:37 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 18 May 2016 13:37:42 +0000 (15:37 +0200)
src/org/mxchange/jmailee/model/delivery/BaseMailer.java
src/org/mxchange/jmailee/model/delivery/DeliverableEmail.java

index 361ce5d58c5a90241ab63e454b4b9afe3ae871ac..851205d6e24a70eed883760961fadb1ed75bc160 100644 (file)
@@ -59,10 +59,10 @@ public abstract class BaseMailer implements DeliverableEmail {
        /**
         * Properties for this mailer
         * <p>
-        * 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.
         * <p>
@@ -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
                }
index 6c8343377df01f3a19256fd95e297db61ba09aa1..895dda8f9f499bd6ab2d97d64b0c39e64ee72965 100644 (file)
@@ -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.
+        * <p>
+        * @param properties Properties instance
+        */
+       void init (final Properties properties);
+
 }