Skip to content

Commit 0f6fe10

Browse files
authored
Merge pull request #4198 from gchq/gh-4175-email-sender
PR for #4175 - Error in EmailSender
2 parents 6b8dcff + cb847d3 commit 0f6fe10

File tree

7 files changed

+111
-3
lines changed

7 files changed

+111
-3
lines changed

build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ ext.versions = [
136136
kafka : '3.6.0',
137137
okhttp : '4.12.0',
138138
poi : '5.2.4',
139+
simple_java_mail : '8.3.1',
139140
swagger : '2.2.18',
140141
unirest : '1.4.9',
141142
zookeeper : '3.4.8', // Roughly pegged to the server version used by Cloudera, see links above. This version is forced below.
@@ -290,7 +291,8 @@ ext.libs = [
290291
poi_ooxml : "org.apache.poi:poi-ooxml:${versions.poi}",
291292
restygwt : "org.fusesource.restygwt:restygwt:2.2.7",
292293
saxon_he : "net.sf.saxon:Saxon-HE:9.9.1-8",
293-
simple_java_mail : 'org.simplejavamail:simple-java-mail:8.3.1',
294+
simple_java_mail : "org.simplejavamail:simple-java-mail:${versions.simple_java_mail}",
295+
simple_java_mail_batch_module : "org.simplejavamail:batch-module:${versions.simple_java_mail}",
294296
slf4j_api : "org.slf4j:slf4j-api", // version controlled by dropwizard-dependencies
295297
snake_yaml : "org.yaml:snakeyaml:2.2",
296298
solrj : "org.apache.solr:solr-solrj:8.2.0",

stroom-analytics/stroom-analytics-impl/build.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ dependencies {
4747
implementation libs.restygwt
4848
implementation libs.saxon_he
4949
implementation libs.simple_java_mail
50+
implementation libs.simple_java_mail_batch_module
5051
implementation libs.slf4j_api
5152
implementation libs.ws_rs_api
53+
54+
testImplementation libs.assertj_core
55+
testImplementation libs.guice_extension
56+
testImplementation libs.junit_jupiter_api
57+
testImplementation libs.mockito_core
58+
testImplementation libs.mockito_junit_jupiter
59+
60+
// The following logging libs are needed when running junits outside dropwizard
61+
testRuntimeOnly libs.jakarta_activation
62+
testRuntimeOnly libs.jaxb_impl
63+
testRuntimeOnly libs.jcl_over_slf4j
64+
testRuntimeOnly libs.jul_to_slf4j
65+
testRuntimeOnly libs.junit_jupiter_engine
66+
testRuntimeOnly libs.log4j_over_slf4j
67+
testRuntimeOnly libs.logback_classic
68+
testRuntimeOnly libs.logback_core
5269
}

stroom-analytics/stroom-analytics-impl/src/main/java/stroom/analytics/impl/AnalyticsConfig.java

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public CacheConfig getStreamingAnalyticCache() {
8282
return streamingAnalyticCache;
8383
}
8484

85+
86+
// --------------------------------------------------------------------------------
87+
88+
8589
@BootStrapConfig
8690
public static class AnalyticsDbConfig extends AbstractDbConfig implements IsStroomConfig {
8791

stroom-analytics/stroom-analytics-impl/src/main/java/stroom/analytics/impl/SmtpConfig.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
@JsonPropertyOrder(alphabetic = true)
3939
public class SmtpConfig extends AbstractConfig implements IsStroomConfig {
4040

41+
public static final String DEFAULT_TRANSPORT = "plain";
42+
4143
@NotNull
4244
@JsonProperty("host")
4345
@JsonPropertyDescription("The fully qualified hostname of the SMTP server.")
@@ -66,7 +68,7 @@ public class SmtpConfig extends AbstractConfig implements IsStroomConfig {
6668
public SmtpConfig() {
6769
host = "localhost";
6870
port = 2525;
69-
transport = "plain";
71+
transport = DEFAULT_TRANSPORT;
7072
password = null;
7173
username = null;
7274
}
@@ -85,6 +87,11 @@ public SmtpConfig(@JsonProperty("host") final String host,
8587
this.password = password;
8688
}
8789

90+
public static SmtpConfig unauthenticated(final String host,
91+
final int port) {
92+
return new SmtpConfig(host, port, DEFAULT_TRANSPORT, null, null);
93+
}
94+
8895
public String getHost() {
8996
return host;
9097
}
@@ -110,7 +117,7 @@ public TransportStrategy getTransportStrategy() {
110117
switch (transport) {
111118
case "TLS", "SSL":
112119
return TransportStrategy.SMTP_TLS;
113-
case "plain":
120+
case DEFAULT_TRANSPORT:
114121
default:
115122
return TransportStrategy.SMTP;
116123
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package stroom.analytics.impl;
2+
3+
import stroom.analytics.shared.AnalyticNotificationEmailDestination;
4+
5+
import org.junit.jupiter.api.Disabled;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.extension.ExtendWith;
8+
import org.mockito.Mock;
9+
import org.mockito.Mockito;
10+
import org.mockito.junit.jupiter.MockitoExtension;
11+
12+
import java.util.UUID;
13+
14+
@ExtendWith(MockitoExtension.class)
15+
class TestEmailSender {
16+
17+
@Mock
18+
private AnalyticsConfig mockAnalyticsConfig;
19+
20+
@Disabled // manual only due to reliance on smtp.freesmtpservers.com
21+
@Test
22+
void send() {
23+
// See https://www.wpoven.com/tools/free-smtp-server-for-testing to check the email sent
24+
Mockito.when(mockAnalyticsConfig.getEmailConfig())
25+
.thenReturn(new EmailConfig(
26+
SmtpConfig.unauthenticated("smtp.freesmtpservers.com", 25),
27+
28+
"Mr Foo"));
29+
30+
final EmailSender emailSender = new EmailSender(() -> mockAnalyticsConfig);
31+
32+
final AnalyticNotificationEmailDestination destination = AnalyticNotificationEmailDestination.builder()
33+
34+
.build();
35+
36+
final Detection detection = new Detection(
37+
null,
38+
"DetectorName",
39+
UUID.randomUUID().toString(),
40+
null,
41+
null,
42+
"Headline",
43+
null,
44+
null,
45+
UUID.randomUUID().toString(),
46+
null,
47+
null,
48+
null,
49+
null);
50+
51+
emailSender.send(destination, detection);
52+
}
53+
}

stroom-security/stroom-security-identity/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies {
4343
implementation libs.jaxb_api
4444
implementation libs.jose4j
4545
implementation libs.simple_java_mail
46+
implementation libs.simple_java_mail_batch_module
4647
implementation libs.slf4j_api
4748
implementation libs.swagger_annotations
4849
implementation libs.ws_rs_api
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
* Issue **#4175** : Fix `Batch module not found` error when sending emails.
2+
3+
4+
```sh
5+
# ********************************************************************************
6+
# Issue title: Error in EmailSender
7+
# Issue link: https://github.com/gchq/stroom/issues/4175
8+
# ********************************************************************************
9+
10+
# ONLY the top line will be included as a change entry in the CHANGELOG.
11+
# The entry should be in GitHub flavour markdown and should be written on a SINGLE
12+
# line with no hard breaks. You can have multiple change files for a single GitHub issue.
13+
# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than
14+
# 'Fixed nasty bug'.
15+
#
16+
# Examples of acceptable entries are:
17+
#
18+
#
19+
# * Issue **123** : Fix bug with an associated GitHub issue in this repository
20+
#
21+
# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository
22+
#
23+
# * Fix bug with no associated GitHub issue.
24+
```

0 commit comments

Comments
 (0)