Skip to content

Commit

Permalink
Email notification plumbing
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgaldi committed Aug 12, 2024
1 parent 42c55ac commit 95e0f29
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Model/src/main/java/org/gusdb/wdk/model/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ public String getSmtpServer() {
return _smtpServer;
}

public Optional<String> getSmtpUserName() {
return _smtpUserName;
}

public Optional<String> getSmtpPassword() {
return _smtpPassword;
}

/**
* @return Returns the emailContent.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 + "\\$\\$",
Expand All @@ -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[]{});
}
}

0 comments on commit 95e0f29

Please sign in to comment.