]> git.mxchange.org Git - jmailer-ee.git/blobdiff - src/org/mxchange/jmailee/model/delivery/BaseMailer.java
updated own name and resources
[jmailer-ee.git] / src / org / mxchange / jmailee / model / delivery / BaseMailer.java
index 361ce5d58c5a90241ab63e454b4b9afe3ae871ac..8c75fbea147d7afb3abfbe058fdba21c8e21ee05 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -41,7 +41,7 @@ import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
 /**
  * An email class for sending out mails from templates
  * <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
  */
 public abstract class BaseMailer implements DeliverableEmail {
 
@@ -98,6 +98,31 @@ public abstract class BaseMailer implements DeliverableEmail {
                return this.templateEngine;
        }
 
+       @Override
+       @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+       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 +134,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);
 
@@ -120,24 +154,23 @@ public abstract class BaseMailer implements DeliverableEmail {
                message.setHeader("MIME-Version", "1.0"); //NOI18N
                message.setHeader("Content-Type", "text/plain; charset=UTF-8"); //NOI18N
                message.setHeader("Content-Transfer-Encoding", "8bit"); //NOI18N
-               message.setHeader("Errors-To", this.properties.getProperty("mailer.errorsto")); //NOI18N
+
+               // Is property "errorsto" set ?
+               if ((this.properties.containsKey("mailer.errorsto")) && (!this.properties.getProperty("mailer.errorsto").isEmpty())) { //NOI18N
+                       // Use this
+                       message.setHeader("Errors-To", this.properties.getProperty("mailer.errorsto")); //NOI18N#
+               }
 
                // Is the property "bouncesto" set?
-               if (this.properties.containsKey("mailer.bouncesto")) { //NOI18N
+               if ((this.properties.containsKey("mailer.bouncesto")) && (!this.properties.getProperty("mailer.bouncesto").isEmpty())) { //NOI18N
                        // Use this
                        message.setHeader("Bounces-To", this.properties.getProperty("mailer.bouncesto")); //NOI18N
-               } else {
-                       // Use "errorsto"
-                       message.setHeader("Bounces-To", this.properties.getProperty("mailer.errorsto")); //NOI18N
                }
 
                // Is the property "xloop" set?
-               if (this.properties.containsKey("mailer.xloop")) { //NOI18N
+               if ((this.properties.containsKey("mailer.xloop")) && (!this.properties.getProperty("mailer.xloop").isEmpty())) { //NOI18N
                        // Use this
                        message.setHeader("X-Loop", this.properties.getProperty("mailer.xloop")); //NOI18N
-               } else {
-                       // Use "errorsto"
-                       message.setHeader("X-Loop", this.properties.getProperty("mailer.errorsto")); //NOI18N
                }
 
                // Directly send email
@@ -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
                }