From: Roland Häder Date: Fri, 7 Jul 2017 22:21:31 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4f027d1664cdc2127e893d12f1e8d1501b982b76;p=jfinancials-mailer-lib.git Please cherry-pick: - @Resource is not working in any unmanaged classes (like ordinary classes are) - so let's try it with the annotation-free JNDI lookup over InitialContext - the constructor may throw now a NamingException if the JNDI lookup failed - please note, the short name is now generally "smtpSession" Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/addressbook/mailer/model/delivery/AddressbookMailer.java b/src/org/mxchange/addressbook/mailer/model/delivery/AddressbookMailer.java index e0e9a5b..f308689 100644 --- a/src/org/mxchange/addressbook/mailer/model/delivery/AddressbookMailer.java +++ b/src/org/mxchange/addressbook/mailer/model/delivery/AddressbookMailer.java @@ -18,9 +18,11 @@ package org.mxchange.addressbook.mailer.model.delivery; import java.text.MessageFormat; import java.util.Map; -import javax.annotation.Resource; import javax.mail.MessagingException; import javax.mail.Session; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.mxchange.jmailee.model.delivery.BaseMailer; @@ -41,8 +43,20 @@ public class AddressbookMailer extends BaseMailer implements DeliverableAddressb /** * Email session */ - @Resource (name = "jmail/addressbook", description = "A JavaMail resource") - private Session mailSession; + private final Session mailSession; + + /** + * Default constructor + *

+ * @throws javax.naming.NamingException If the JNDI name is not found + */ + public AddressbookMailer () throws NamingException { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.mailSession = (Session) context.lookup("java:global/jfinancials-mailer/smtpSession"); //NOI18N + } @Override public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException { @@ -53,9 +67,9 @@ public class AddressbookMailer extends BaseMailer implements DeliverableAddressb if (null == emailWrapper) { // Throw NPE throw new NullPointerException("emailWrapper is null"); //NOI18N - } else if (emailWrapper.getRecipient() == null) { + } else if (emailWrapper.getRecipientAddress() == null) { // Throw NPE again - throw new NullPointerException("emailWrapper.recipient is null"); //NOI18N + throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N } else if (emailWrapper.getSubjectLine() == null) { // ... and again throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N