]> git.mxchange.org Git - jmailer-ee.git/commitdiff
Lesser method calls in another method call + lesser parameter = better style ... ;-)
authorRoland Häder <roland@mxchange.org>
Thu, 6 Jul 2017 20:31:48 +0000 (22:31 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 6 Jul 2017 20:31:48 +0000 (22:31 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jmailee/model/delivery/BaseMailer.java

index 843bada72d4f2551bf678ed5020e277bca270ce4..2e677f7a625513aa37dcd77951571a5b902dc100 100644 (file)
@@ -20,7 +20,6 @@ import java.io.StringWriter;
 import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Properties;
-import javax.mail.Address;
 import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.mail.Transport;
@@ -128,14 +127,14 @@ public abstract class BaseMailer implements DeliverableEmail {
         * <p>
         * @param emailAddress Email address for recipient
         * @param subjectLine Subject line
-        * @param body Body part
+        * @param writer Body part
         * @param mailSession Corresponding mail session to use
         * <p>
         * @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 {
+       private void sendMail (final WrapableEmailDelivery emailWrapper, final StringWriter writer, 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
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendMail: emailWrapper={0},body={1},mailSession={2} - CALLED!", emailWrapper, writer, mailSession)); //NOI18N
 
                // Are the additional properties set?
                if (null == this.properties) {
@@ -147,10 +146,10 @@ public abstract class BaseMailer implements DeliverableEmail {
                MimeMessage message = new MimeMessage(mailSession);
 
                // Set subject, recipients and body
-               message.setSubject(subjectLine);
-               message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailAddress.toString(), true));
+               message.setSubject(emailWrapper.getSubjectLine());
+               message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailWrapper.getRecipient().toString(), true));
                message.setSentDate(new Date());
-               message.setText(body);
+               message.setText(writer.toString());
                message.setHeader("MIME-Version", "1.0"); //NOI18N
                message.setHeader("Content-Type", "text/plain; charset=UTF-8"); //NOI18N
                message.setHeader("Content-Transfer-Encoding", "8bit"); //NOI18N
@@ -175,6 +174,9 @@ public abstract class BaseMailer implements DeliverableEmail {
 
                // Directly send email
                Transport.send(message);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N
        }
 
        /**
@@ -234,7 +236,10 @@ public abstract class BaseMailer implements DeliverableEmail {
                template.merge(context, writer);
 
                // Get all out and send it
-               this.sendMail(emailWrapper.getRecipient(), emailWrapper.getSubjectLine(), writer.toString(), mailSession);
+               this.sendMail(emailWrapper, writer, mailSession);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N
        }
 
 }