From 95e0f29bbe540e664c757586744cb0018ba80598 Mon Sep 17 00:00:00 2001 From: Dan Galdi Date: Mon, 12 Aug 2024 13:40:43 -0400 Subject: [PATCH] Email notification plumbing --- Model/src/main/java/org/gusdb/wdk/model/Utilities.java | 3 +-- .../main/java/org/gusdb/wdk/model/config/ModelConfig.java | 8 ++++++++ .../org/gusdb/wdk/model/user/UserPasswordEmailer.java | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Model/src/main/java/org/gusdb/wdk/model/Utilities.java b/Model/src/main/java/org/gusdb/wdk/model/Utilities.java index 73a963296..209732c6b 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/Utilities.java +++ b/Model/src/main/java/org/gusdb/wdk/model/Utilities.java @@ -228,8 +228,7 @@ public static void sendEmail(String smtpServer, String sendTos, String reply, // sendEmail() all 10 parameters public static void sendEmail(String smtpServer, String username, String password, String sendTos, String reply, - String subject, String content, String ccAddresses, String bccAddresses, - Attachment[] attachments) throws WdkModelException { + String subject, String content, String ccAddresses, String bccAddresses, Attachment[] attachments) throws WdkModelException { LOG.debug("Sending message to: " + sendTos + ", bcc to: " + bccAddresses + ",reply: " + reply + ", using SMPT: " + smtpServer); diff --git a/Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java b/Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java index 60f87e8d2..feea6767a 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java +++ b/Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java @@ -269,6 +269,14 @@ public String getSmtpServer() { return _smtpServer; } + public Optional getSmtpUserName() { + return _smtpUserName; + } + + public Optional getSmtpPassword() { + return _smtpPassword; + } + /** * @return Returns the emailContent. */ diff --git a/Model/src/main/java/org/gusdb/wdk/model/user/UserPasswordEmailer.java b/Model/src/main/java/org/gusdb/wdk/model/user/UserPasswordEmailer.java index 7a083f706..99602422a 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/user/UserPasswordEmailer.java +++ b/Model/src/main/java/org/gusdb/wdk/model/user/UserPasswordEmailer.java @@ -1,7 +1,9 @@ package org.gusdb.wdk.model.user; +import java.util.Optional; import java.util.regex.Matcher; +import org.gusdb.wdk.model.Attachment; import org.gusdb.wdk.model.Utilities; import org.gusdb.wdk.model.WdkModel; import org.gusdb.wdk.model.WdkModelException; @@ -37,6 +39,10 @@ public void emailTemporaryPassword(User user, String password) throws WdkModelEx String supportEmail = wdkModelConfig.getSupportEmail(); String emailSubject = wdkModelConfig.getEmailSubject(); + // Unwrap optionals here to maintain consistency with nullable arguments in Utilities.sendEmail method. + String smtpUser = wdkModelConfig.getSmtpUserName().orElse(null); + String smtpPass = wdkModelConfig.getSmtpPassword().orElse(null); + // populate email content macros with user data String emailContent = wdkModelConfig.getEmailContent() .replaceAll("\\$\\$" + EMAIL_MACRO_USER_NAME + "\\$\\$", @@ -46,6 +52,6 @@ public void emailTemporaryPassword(User user, String password) throws WdkModelEx .replaceAll("\\$\\$" + EMAIL_MACRO_PASSWORD + "\\$\\$", Matcher.quoteReplacement(password)); - Utilities.sendEmail(smtpServer, user.getEmail(), supportEmail, emailSubject, emailContent); + Utilities.sendEmail(smtpServer, user.getEmail(), supportEmail, emailSubject, emailContent, null, null, smtpUser, smtpPass, new Attachment[]{}); } }