Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable mail MTA/SMTP configuration using MicroProfile Config #9939

Merged
merged 81 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
d6c0600
feat(mail): add MTA settings for mail to JvmSettings #7424
poikilotherm Sep 19, 2023
de759c1
feat(mail): add minimal implementation of a mail session factory #7424
poikilotherm Sep 20, 2023
72cdde9
feat(mail): add sane defaults for mail jvm settings at app level #7424
poikilotherm Sep 20, 2023
02f1c3d
feat(mail): inject mail session via CDI from factory in MailServiceBe…
poikilotherm Sep 20, 2023
1f79f57
fix(mail): make error logs about missing mapping file go away #7424
poikilotherm Sep 20, 2023
03b11bf
feat(ct,mail): no longer configure mail in containers manually #7424
poikilotherm Sep 20, 2023
ee88cfd
doc(ct): remove mail env vars from app image docs #7424
poikilotherm Sep 20, 2023
600d209
build(test): enable using GenericContainer without JUnit4 around
poikilotherm Sep 20, 2023
6f6a9b7
fix(mail): correct typo in mail.smtp prefix string #7424
poikilotherm Sep 20, 2023
c23ccde
chore(build,test): upgrade to Testcontainers v1.19.0
poikilotherm Sep 20, 2023
eb1664f
feat(mail): add explicit injection constructor to MailServiceBean #7424
poikilotherm Sep 20, 2023
086f766
test(mail): add integration test for mail session configuration and u…
poikilotherm Sep 20, 2023
51af5e1
build(mail): exclude geronimo javamail spec from dependencies
poikilotherm Sep 20, 2023
36d78fd
feat(mail): enable backward compat for javamail resource from app ser…
poikilotherm Sep 24, 2023
b612e1a
doc(mail): add initial release note for deprecated mail config #7424
poikilotherm Sep 24, 2023
bc55587
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Oct 5, 2023
c367e09
test(mail): refactor IT for mail sessions to use @JvmSettings
poikilotherm Oct 5, 2023
4c64051
test(mail): include in regular IT test suite
poikilotherm Oct 5, 2023
2178c83
test(mail): add test scenario including necessary SMTP authentication…
poikilotherm Oct 5, 2023
17aa5ad
feat(mail): make system email address configurable via MPCONFIG #7424
poikilotherm Oct 6, 2023
fd41607
refactor(mail): make MailServiceBean use new lookup API for system ad…
poikilotherm Oct 6, 2023
2bff977
feat(mail): provide lookup function for support mail address #7424
poikilotherm Oct 6, 2023
de2f423
refactor(mail): replace manual parsing with mail service lookups #7424
poikilotherm Oct 6, 2023
81da403
style(mail): deprecate db setting for system email #7424
poikilotherm Oct 6, 2023
59b09cb
test(mail): use InternetAddress parsing directly, no need for MailUtil
poikilotherm Oct 6, 2023
7fc613f
refactor(mail): remove unused MailUtil.parseSystemAddress #7424
poikilotherm Oct 6, 2023
5b418c0
test(mail): refactor IT with new system email JVM option #7424
poikilotherm Oct 6, 2023
2c3e054
test(mail): restructure and add test for mail address lookups working…
poikilotherm Oct 6, 2023
8fac0f6
test,fix(branding): make mock adding methods lenient to avoid unneces…
poikilotherm Oct 6, 2023
9c7d9b5
refactor(mail): simplify MailServiceBean.sendSystemEmail #7424
poikilotherm Oct 9, 2023
b970eb5
feat(mail): enable UTF-8 mail address following RFC 6530 #7424
poikilotherm Oct 10, 2023
05870d1
fix(mail): lookup UTF-8 support config in static method to pick up ch…
poikilotherm Oct 10, 2023
e9abfd2
fix(mail): add missing mock in MailServiceBeanTest
poikilotherm Oct 10, 2023
7d1ba87
fix(mail): make mail configuration entirely optional #7424
poikilotherm Oct 10, 2023
df53751
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Oct 10, 2023
7a23d1a
chore(build): update to Testcontainers 1.19.1
poikilotherm Oct 11, 2023
4bfda6c
chore(build): update to SmallRye Config 3.4.1
poikilotherm Oct 11, 2023
b74d60f
chore(build): update Mockito to v5.6.0
poikilotherm Oct 11, 2023
078d6d7
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Oct 15, 2023
b194263
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Nov 8, 2023
9397cc3
fix(mail): lookup legacy mail session programmatically #7424
poikilotherm Nov 8, 2023
d650725
build(mail): add .map files to be included in resources #7424
poikilotherm Nov 8, 2023
11826d9
feat(mail): add startup checks for mail configuration #7424
poikilotherm Nov 8, 2023
4efef85
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Jan 17, 2024
213b025
test(mail): add more tests for mail session producer with invalid config
poikilotherm Feb 16, 2024
7ff1e17
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Feb 16, 2024
084fa32
chore(test): remove leftover JUnit 4 rules
poikilotherm Feb 20, 2024
4d3904f
test(mail): verify SMTP over SSL/TLS works
poikilotherm Feb 20, 2024
53e964a
style(mail): update deprecation tags for DV v6.2
poikilotherm Feb 20, 2024
abcb131
style(settings): ignore SonarCube rule S115 for DB settings
poikilotherm Feb 20, 2024
b0d268d
doc(settings): add section on secure password storage in security sec…
poikilotherm Feb 20, 2024
f690c47
feat(installer): make installer use new way to apply mail MTA config
poikilotherm Feb 20, 2024
9824425
doc(mail): add mail config paragraphs #7424
poikilotherm Feb 20, 2024
5dcaba9
doc(mail): rewrite install docs to match new way of mail config #7424
poikilotherm Feb 20, 2024
a48e860
fix(ct): migrate compose and configbaker to use new way of mail config
poikilotherm Feb 20, 2024
6f5cc9f
style(mail): update mail config release note
poikilotherm Feb 20, 2024
930fc1b
style(mail): update mail config release note about source of from add…
poikilotherm Feb 20, 2024
d82cff4
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Feb 21, 2024
e11a623
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Mar 12, 2024
af7171e
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Mar 21, 2024
6b15b12
Merge branch 'develop' into 7424-maildefinition-ng
poikilotherm Mar 22, 2024
db9cd86
docs(mail): apply suggestions from code review
poikilotherm Mar 25, 2024
83d29b1
feat(ct): add MTA config to demo compose #7424
poikilotherm Mar 25, 2024
ff3b1a1
Merge remote-tracking branch 'origin/7424-maildefinition-ng' into 742…
poikilotherm Mar 25, 2024
ac74b23
removed outdated "problems sending email" section #9939
pdurbin Mar 25, 2024
f263a4e
update docs and release note #7424
pdurbin Mar 25, 2024
caf5682
link higher up in the guides #7424
pdurbin Mar 25, 2024
362b87e
fix(mail): remove duplicate JvmSettings.MAIL_MTA_HOST
poikilotherm Mar 26, 2024
b8ca4a7
fix(mail): do not add a default for SMPT host in ct profile
poikilotherm Mar 26, 2024
d8198b5
style(mail): enable more debug output from session producer
poikilotherm Mar 26, 2024
2a73426
fix(mail): do not fail to deploy when debugging is not configured
poikilotherm Mar 26, 2024
21aa73d
style(mail): applying better fix for default value of mail debugging
poikilotherm Mar 26, 2024
3619371
fix dot to dash
pdurbin Mar 26, 2024
c498ceb
doc(mail): add ssl.enable setting to shortlist
poikilotherm Mar 26, 2024
5d7a863
Merge remote-tracking branch 'origin/7424-maildefinition-ng' into 742…
poikilotherm Mar 26, 2024
3e9d992
doc(mail): add newly added settings to release note
poikilotherm Mar 26, 2024
785dfc5
chore(build): update Maven and test framework dependencies
poikilotherm Mar 26, 2024
6b8b907
chore(build): downgrade DMP to 0.43.4
poikilotherm Mar 26, 2024
df48382
simply smtp config docs #7424
pdurbin Mar 26, 2024
cb14423
doc(mail): fix some typos, add hint about support in new SMTP config …
poikilotherm Mar 26, 2024
e784eb3
point release note at new SMTP section #7424
pdurbin Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/release-notes/7424-mailsession.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## New way to configure mail transfer agent

With this release, we deprecate the usage of `asadmin create-javamail-resource` to configure your MTA.
Instead, we provide the ability to configure your SMTP mail host using JVM options with the flexibility of MicroProfile Config.

At this point, no action is required if you want to keep your current configuration.
Warnings will show in your server logs to inform and remind you about the deprecation.
A future major release of Dataverse may remove this way of configuration.
13 changes: 0 additions & 13 deletions doc/sphinx-guides/source/container/app-image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,6 @@ In addition, the application image provides the following tunables:

1. Simply pick a JVM option from the list and replace any ``.`` with ``_``.
2. Replace any ``-`` in the option name with ``__``.
* - ``DATAVERSE_MAIL_HOST``
- ``smtp``
- String
- A hostname (w/o port!) where to reach a Mail MTA on port 25.
* - ``DATAVERSE_MAIL_USER``
- ``dataversenotify``
- String
- A username to use with the Mail MTA
* - ``DATAVERSE_MAIL_FROM``
- ``dataverse@localhost``
- Mail address
- The "From" field for all outbound mail. Make sure to set :ref:`systemEmail` to the same value or no mail will
be sent.


Note that the script ``init_2_configure.sh`` will apply a few very important defaults to enable quick usage
Expand Down
6 changes: 3 additions & 3 deletions modules/dataverse-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@
<gdcc.xoai.version>5.2.0</gdcc.xoai.version>

<!-- Testing dependencies -->
<testcontainers.version>1.19.0</testcontainers.version>
<smallrye-mpconfig.version>2.10.1</smallrye-mpconfig.version>
<testcontainers.version>1.19.1</testcontainers.version>
<smallrye-mpconfig.version>3.4.1</smallrye-mpconfig.version>
<junit.jupiter.version>5.10.0</junit.jupiter.version>
<mockito.version>5.4.0</mockito.version>
<mockito.version>5.6.0</mockito.version>
<maven-jacoco-plugin.version>0.8.10</maven-jacoco-plugin.version>

<checkstyle.version>9.3</checkstyle.version>
Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@
<artifactId>abdera-i18n</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.abdera</groupId>
<artifactId>abdera-parser</artifactId>
<version>1.1.3</version>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-javamail_1.4_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Declare any DIRECT dependencies here.
Expand Down Expand Up @@ -677,6 +688,7 @@
<include>**/firstNames/*.*</include>
<include>**/*.xsl</include>
<include>**/services/*</include>
<include>**/*.map</include>
</includes>
</resource>
<resource>
Expand Down
4 changes: 0 additions & 4 deletions src/main/docker/scripts/init_2_configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ echo "# Dataverse postboot configuration for Payara" > "${DV_POSTBOOT}"
# EE 8 code annotations or at least glassfish-resources.xml
# NOTE: postboot commands is not multi-line capable, thus spaghetti needed.

# JavaMail
echo "INFO: Defining JavaMail."
echo "create-javamail-resource --mailhost=${DATAVERSE_MAIL_HOST:-smtp} --mailuser=${DATAVERSE_MAIL_USER:-dataversenotify} --fromaddress=${DATAVERSE_MAIL_FROM:-dataverse@localhost} mail/notifyMailSession" >> "${DV_POSTBOOT}"

# 3. Domain based configuration options
# Set Dataverse environment variables
echo "INFO: Defining system properties for Dataverse configuration options."
Expand Down
168 changes: 114 additions & 54 deletions src/main/java/edu/harvard/iq/dataverse/MailServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import edu.harvard.iq.dataverse.branding.BrandingUtil;
import edu.harvard.iq.dataverse.confirmemail.ConfirmEmailServiceBean;
import edu.harvard.iq.dataverse.dataset.DatasetUtil;
import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean.Key;
import edu.harvard.iq.dataverse.util.BundleUtil;
Expand All @@ -24,11 +25,15 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.mail.Address;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
Expand Down Expand Up @@ -78,77 +83,133 @@ public class MailServiceBean implements java.io.Serializable {
*/
public MailServiceBean() {
}

/**
* Creates a new instance of MailServiceBean with explicit injection, as used during testing.
*/
public MailServiceBean(Session session, SettingsServiceBean settingsService) {
this.session = session;
this.settingsService = settingsService;
}

@Resource(name = "mail/notifyMailSession")
@Inject
@Named("mail/systemSession")
private Session session;

public boolean sendSystemEmail(String to, String subject, String messageText) {
return sendSystemEmail(to, subject, messageText, false);
}


/**
* Send a system notification to one or multiple recipients by email.
* Will skip sending when {@link #getSystemAddress()} doesn't return a configured "from" address.
* @param to A comma separated list of one or multiple recipients' addresses. May contain a "personal name" and
* the recipients address in &lt;&gt;. See also {@link InternetAddress}.
* @param subject The message's subject
* @param messageText The message's text
* @param isHtmlContent Determine if the message text is formatted using HTML or plain text.
* @return Status: true if sent successfully, false otherwise
*/
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)))
: BundleUtil.getStringFromBundle("notification.email.closing", Arrays.asList(BrandingUtil.getSupportTeamEmailAddress(systemAddress), BrandingUtil.getSupportTeamName(systemAddress))));
String body = messageText +
BundleUtil.getStringFromBundle(isHtmlContent ? "notification.email.closing.html" : "notification.email.closing",
List.of(BrandingUtil.getSupportTeamEmailAddress(systemAddress), BrandingUtil.getSupportTeamName(systemAddress)));

logger.fine("Sending email to " + to + ". Subject: <<<" + subject + ">>>. Body: " + body);
logger.fine(() -> "Sending email to %s. Subject: <<<%s>>>. Body: %s".formatted(to, subject, body));
try {
// Since JavaMail 1.6, we have support for UTF-8 mail addresses and do not need to handle these ourselves.
InternetAddress[] recipients = InternetAddress.parse(to);

MimeMessage msg = new MimeMessage(session);
if (systemAddress != null) {
msg.setFrom(systemAddress);
msg.setSentDate(new Date());
String[] recipientStrings = to.split(",");
InternetAddress[] recipients = new InternetAddress[recipientStrings.length];
for (int i = 0; i < recipients.length; i++) {
try {
recipients[i] = new InternetAddress(recipientStrings[i], "", charset);
} catch (UnsupportedEncodingException ex) {
logger.severe(ex.getMessage());
}
}
msg.setRecipients(Message.RecipientType.TO, recipients);
msg.setSubject(subject, charset);
if (isHtmlContent) {
msg.setText(body, charset, "html");
} else {
msg.setText(body, charset);
}

try {
Transport.send(msg, recipients);
sent = true;
} catch (MessagingException ssfe) {
logger.warning("Failed to send mail to: " + to);
logger.warning("MessagingException Message: " + ssfe);
}
msg.setFrom(systemAddress);
msg.setSentDate(new Date());
msg.setRecipients(Message.RecipientType.TO, recipients);
msg.setSubject(subject, charset);
if (isHtmlContent) {
msg.setText(body, charset, "html");
} else {
logger.fine("Skipping sending mail to " + to + ", because the \"no-reply\" address not set (" + Key.SystemEmail + " setting).");
msg.setText(body, charset);
}
} catch (AddressException ae) {
logger.warning("Failed to send mail to " + to);
ae.printStackTrace(System.out);
} catch (MessagingException me) {
logger.warning("Failed to send mail to " + to);
me.printStackTrace(System.out);
Transport.send(msg, recipients);
return true;
} catch (MessagingException ae) {
logger.log(Level.WARNING, "Failed to send mail to %s: %s".formatted(to, ae.getMessage()), ae);
logger.info("When UTF-8 characters in recipients: make sure MTA supports it and JVM option " + JvmSettings.MAIL_MTA_SUPPORT_UTF8.getScopedKey() + "=true");
}
return sent;
return false;
}

public InternetAddress getSystemAddress() {
String systemEmail = settingsService.getValueForKey(Key.SystemEmail);
return MailUtil.parseSystemAddress(systemEmail);

/**
* Lookup the system mail address ({@code InternetAddress} may contain personal and actual address).
* @return The system mail address or an empty {@code Optional} if not configured.
*/
public Optional<InternetAddress> getSystemAddress() {
boolean providedByDB = false;
String mailAddress = JvmSettings.SYSTEM_EMAIL.lookupOptional().orElse(null);

// Try lookup of (deprecated) database setting only if not configured via MPCONFIG
if (mailAddress == null) {
mailAddress = settingsService.getValueForKey(Key.SystemEmail);
// Encourage people to migrate from deprecated setting
if (mailAddress != null) {
providedByDB = true;
logger.warning("The :SystemMail DB setting has been deprecated, please reconfigure using JVM option " + JvmSettings.SYSTEM_EMAIL.getScopedKey());
}
}

try {
// Parse and return.
return Optional.of(new InternetAddress(Objects.requireNonNull(mailAddress), true));
} catch (AddressException e) {
logger.log(Level.WARNING, "Could not parse system mail address '%s' provided by %s: "
.formatted(providedByDB ? "DB setting" : "JVM option", mailAddress), e);
} catch (NullPointerException e) {
// Do not pester the logs - no configuration may mean someone wants to disable mail notifications
logger.fine("Could not find a system mail setting in database (key :SystemEmail, deprecated) or JVM option '" + JvmSettings.SYSTEM_EMAIL.getScopedKey() + "'");
}
// We define the system email address as an optional setting, in case people do not want to enable mail
// notifications (like in a development context, but might be useful elsewhere, too).
return Optional.empty();
}

/**
* Lookup the support team mail address ({@code InternetAddress} may contain personal and actual address).
* Will default to return {@code #getSystemAddress} if not configured.
* @return Support team mail address
*/
public Optional<InternetAddress> getSupportAddress() {
Optional<String> supportMailAddress = JvmSettings.SUPPORT_EMAIL.lookupOptional();
if (supportMailAddress.isPresent()) {
try {
return Optional.of(new InternetAddress(supportMailAddress.get(), true));
} catch (AddressException e) {
logger.log(Level.WARNING, "Could not parse support mail address '%s', defaulting to system address: ".formatted(supportMailAddress.get()), e);
}
}
return 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 Expand Up @@ -505,13 +566,12 @@ public String getMessageTextBasedOnNotification(UserNotification userNotificatio
messageText += MessageFormat.format(pattern, paramArrayStatus);
return messageText;
case CREATEACC:
InternetAddress systemAddress = getSystemAddress();
String accountCreatedMessage = BundleUtil.getStringFromBundle("notification.email.welcome", Arrays.asList(
BrandingUtil.getInstallationBrandName(),
systemConfig.getGuidesBaseUrl(),
systemConfig.getGuidesVersion(),
BrandingUtil.getSupportTeamName(systemAddress),
BrandingUtil.getSupportTeamEmailAddress(systemAddress)
BrandingUtil.getSupportTeamName(getSystemAddress().orElse(null)),
BrandingUtil.getSupportTeamEmailAddress(getSystemAddress().orElse(null))
));
String optionalConfirmEmailAddon = confirmEmailService.optionalConfirmEmailAddonMsg(userNotification.getUser());
accountCreatedMessage += optionalConfirmEmailAddon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.MailUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import java.util.Optional;
import java.util.Random;
Expand Down Expand Up @@ -101,8 +100,7 @@ public void initUserInput(ActionEvent ae) {
op1 = Long.valueOf(random.nextInt(10));
op2 = Long.valueOf(random.nextInt(10));
userSum = null;
String supportEmail = JvmSettings.SUPPORT_EMAIL.lookupOptional().orElse(settingsService.getValueForKey(SettingsServiceBean.Key.SystemEmail));
systemAddress = MailUtil.parseSystemAddress(supportEmail);
systemAddress = mailService.getSupportAddress().orElse(null);
poikilotherm marked this conversation as resolved.
Show resolved Hide resolved
}

public Long getOp1() {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class SettingsWrapper implements java.io.Serializable {

@EJB
MetadataBlockServiceBean mdbService;

@EJB
MailServiceBean mailServiceBean;

private Map<String, String> settingsMap;

Expand Down Expand Up @@ -388,14 +391,14 @@ public boolean isDataFilePIDSequentialDependent(){
}

public String getSupportTeamName() {
String systemEmail = getValueForKey(SettingsServiceBean.Key.SystemEmail);
InternetAddress systemAddress = MailUtil.parseSystemAddress(systemEmail);
// TODO: should this be replaced with mailServiceBean.getSupportAddress() to expose a configured support team?
InternetAddress systemAddress = mailServiceBean.getSystemAddress().orElse(null);
return BrandingUtil.getSupportTeamName(systemAddress);
}

public String getSupportTeamEmail() {
String systemEmail = getValueForKey(SettingsServiceBean.Key.SystemEmail);
InternetAddress systemAddress = MailUtil.parseSystemAddress(systemEmail);
// TODO: should this be replaced with mailServiceBean.getSupportAddress() to expose a configured support team?
InternetAddress systemAddress = mailServiceBean.getSystemAddress().orElse(null);
poikilotherm marked this conversation as resolved.
Show resolved Hide resolved
return BrandingUtil.getSupportTeamEmailAddress(systemAddress) != null ? BrandingUtil.getSupportTeamEmailAddress(systemAddress) : BrandingUtil.getSupportTeamName(systemAddress);
}

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/api/FeedbackApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import edu.harvard.iq.dataverse.branding.BrandingUtil;
import edu.harvard.iq.dataverse.feedback.Feedback;
import edu.harvard.iq.dataverse.feedback.FeedbackUtil;
import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.MailUtil;

import jakarta.ejb.EJB;
import jakarta.json.Json;
Expand Down Expand Up @@ -40,7 +37,7 @@ public class FeedbackApi extends AbstractApiBean {
* user input (e.g. to strip potentially malicious html, etc.)!!!!
**/
@POST
public Response submitFeedback(JsonObject jsonObject) throws AddressException {
public Response submitFeedback(JsonObject jsonObject) {
JsonNumber jsonNumber = jsonObject.getJsonNumber("targetId");
DvObject feedbackTarget = null;
if (jsonNumber != null) {
Expand All @@ -51,8 +48,7 @@ public Response submitFeedback(JsonObject jsonObject) throws AddressException {
}
DataverseSession dataverseSession = null;
String userMessage = jsonObject.getString("body");
String systemEmail = JvmSettings.SUPPORT_EMAIL.lookupOptional().orElse(settingsSvc.getValueForKey(SettingsServiceBean.Key.SystemEmail));
InternetAddress systemAddress = MailUtil.parseSystemAddress(systemEmail);
InternetAddress systemAddress = mailService.getSupportAddress().orElse(null);
String userEmail = jsonObject.getString("fromEmail");
String messageSubject = jsonObject.getString("subject");
String baseUrl = systemConfig.getDataverseSiteUrl();
Expand Down
Loading
Loading