*/
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 org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
import org.mxchange.jmailee.model.delivery.BaseMailer;
+import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
/**
* A mailer for JJobs project
@Resource (name = "jmail/addressbook")
private Session mailSession;
+ @Override
+ public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException {
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendDeliverableMail: emailWrapper={0} - CALLED!", emailWrapper)); //NOI18N
+
+ // The parameter must be valid
+ if (null == emailWrapper) {
+ // Throw NPE
+ throw new NullPointerException("emailWrapper is null"); //NOI18N
+ } else if (emailWrapper.getRecipient() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailWrapper.recipient is null"); //NOI18N
+ } else if (emailWrapper.getSubjectLine() == null) {
+ // ... and again
+ throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N
+ } else if (emailWrapper.getSubjectLine().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("emailWrapper.subjectLine is empty"); //NOI18N
+ } else if (emailWrapper.getTemplateName() == null) {
+ // ... and again
+ throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N
+ } else if (emailWrapper.getTemplateName().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("emailWrapper.templateName is empty"); //NOI18N
+ } else if (emailWrapper.getLocale() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailWrapper.locale is null"); //NOI18N
+ }
+
+ // All required data is set, load template
+ Template template = this.getTemplateEngine().getTemplate(String.format("./templates/%s/%s.vm", emailWrapper.getLocale().getLanguage().toLowerCase(), emailWrapper.getTemplateName())); //NOI18N
+
+ // Init context
+ VelocityContext context = new VelocityContext();
+
+ // Are some variables set?
+ if ((emailWrapper.getTemplateVariables() != null) && (!emailWrapper.getTemplateVariables().isEmpty())) {
+ // Add all variables
+ for (Map.Entry<Object, Object> entry : emailWrapper.getTemplateVariables().entrySet()) {
+ // Get key/value
+ String key = (String) entry.getKey();
+ String value = (String) entry.getValue();
+
+ // Both should not be empty
+ if (null == key) {
+ // Throw NPE
+ throw new NullPointerException("key is null"); //NOI18N
+ } else if (null == value) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("value for key={0} is null", key)); //NOI18N
+ }
+
+ // Set it
+ context.put(key, value);
+ }
+ }
+
+ // Send the email
+ this.sendMailTemplate(template, context, emailWrapper, this.mailSession);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("sendDeliverableMail: EXIT!"); //NOI18N
+ }
+
}
*/
package org.mxchange.addressbook.mailer.model.delivery;
+import javax.mail.MessagingException;
import org.mxchange.jmailee.model.delivery.DeliverableEmail;
+import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
/**
* An interface for deliverable emails by JJobs project.
*/
public interface DeliverableAddressbookEmail extends DeliverableEmail {
+ /**
+ * Sends given deliverable mail instance. This must have set a template
+ * name, a recipient address and a subject line set.
+ * <p>
+ * @param emailWrapper Deliverable mail wrapper
+ * @throws MessagingException If something bad happened
+ */
+ void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException;
+
}