Skip to content

Commit

Permalink
refactor(mail): make MailServiceBean use new lookup API for system ad…
Browse files Browse the repository at this point in the history
…dress IQSS#7424

As we changed the lookup function to use Optional<InternetAddress> to enforce the optional
nature of the setting, we now have to change the code using the function.
  • Loading branch information
poikilotherm committed Oct 6, 2023
1 parent 17aa5ad commit fd41607
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/MailServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ public boolean sendSystemEmail(String to, String subject, String messageText) {
}

public boolean sendSystemEmail(String to, String subject, String messageText, boolean isHtmlContent) {
Optional<InternetAddress> optionalAddress = getSystemAddress();
if (optionalAddress.isEmpty()) {
logger.fine(() -> "Skipping sending mail to " + to + ", because no system address has been set.");
return false;
}
InternetAddress systemAddress = optionalAddress.get();

boolean sent = false;
InternetAddress systemAddress = getSystemAddress();

String body = messageText
+ (isHtmlContent ? BundleUtil.getStringFromBundle("notification.email.closing.html", Arrays.asList(BrandingUtil.getSupportTeamEmailAddress(systemAddress), BrandingUtil.getSupportTeamName(systemAddress)))
Expand Down Expand Up @@ -186,10 +191,17 @@ public Optional<InternetAddress> getSystemAddress() {

//@Resource(name="mail/notifyMailSession")
public void sendMail(String reply, String to, String cc, String subject, String messageText) {
Optional<InternetAddress> optionalAddress = getSystemAddress();
if (optionalAddress.isEmpty()) {
logger.fine(() -> "Skipping sending mail to " + to + ", because no system address has been set.");
return;
}
// Always send from system address to avoid email being blocked
InternetAddress fromAddress = optionalAddress.get();

try {
MimeMessage msg = new MimeMessage(session);
// Always send from system address to avoid email being blocked
InternetAddress fromAddress = getSystemAddress();

try {
setContactDelegation(reply, fromAddress);
} catch (UnsupportedEncodingException ex) {
Expand Down

0 comments on commit fd41607

Please sign in to comment.