Skip to content

Commit 2a73ca0

Browse files
committed
Create spring-boot-mail module
1 parent dae7f6d commit 2a73ca0

File tree

28 files changed

+87
-41
lines changed

28 files changed

+87
-41
lines changed

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ include "spring-boot-project:spring-boot-devtools"
6969
include "spring-boot-project:spring-boot-docs"
7070
include "spring-boot-project:spring-boot-jackson"
7171
include "spring-boot-project:spring-boot-jetty"
72+
include "spring-boot-project:spring-boot-mail"
7273
include "spring-boot-project:spring-boot-reactor-netty"
7374
include "spring-boot-project:spring-boot-test"
7475
include "spring-boot-project:spring-boot-testcontainers"

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
optional(project(":spring-boot-project:spring-boot-amqp"))
2121
optional(project(":spring-boot-project:spring-boot-jackson"))
2222
optional(project(":spring-boot-project:spring-boot-jetty"))
23+
optional(project(":spring-boot-project:spring-boot-mail"))
2324
optional(project(":spring-boot-project:spring-boot-reactor-netty"))
2425
optional(project(":spring-boot-project:spring-boot-tomcat"))
2526
optional(project(":spring-boot-project:spring-boot-undertow"))

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mail/MailHealthContributorAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2727
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2828
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
29-
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
29+
import org.springframework.boot.mail.autoconfigure.MailSenderAutoConfiguration;
3030
import org.springframework.context.annotation.Bean;
3131
import org.springframework.mail.javamail.JavaMailSenderImpl;
3232

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/mail/MailHealthContributorAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
2222
import org.springframework.boot.actuate.mail.MailHealthIndicator;
2323
import org.springframework.boot.autoconfigure.AutoConfigurations;
24-
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
24+
import org.springframework.boot.mail.autoconfigure.MailSenderAutoConfiguration;
2525
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2626

2727
import static org.assertj.core.api.Assertions.assertThat;

spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,13 +1648,6 @@
16481648
"name": "spring.liquibase.ui-service",
16491649
"defaultValue": "logger"
16501650
},
1651-
{
1652-
"name": "spring.mail.test-connection",
1653-
"description": "Whether to test that the mail server is available on startup.",
1654-
"sourceType": "org.springframework.boot.autoconfigure.mail.MailProperties",
1655-
"type": "java.lang.Boolean",
1656-
"defaultValue": false
1657-
},
16581651
{
16591652
"name": "spring.mustache.prefix",
16601653
"defaultValue": "classpath:/templates/"

spring-boot-project/spring-boot-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
7777
org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration
7878
org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration
7979
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
80-
org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration
81-
org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration
8280
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
8381
org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration
8482
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,7 @@ bom {
20412041
"spring-boot-loader",
20422042
"spring-boot-loader-classic",
20432043
"spring-boot-loader-tools",
2044+
"spring-boot-mail",
20442045
"spring-boot-properties-migrator",
20452046
"spring-boot-reactor-netty",
20462047
"spring-boot-starter",

spring-boot-project/spring-boot-docs/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies {
5757
autoConfiguration(project(path: ":spring-boot-project:spring-boot-devtools", configuration: "autoConfigurationMetadata"))
5858
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "autoConfigurationMetadata"))
5959
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jetty", configuration: "autoConfigurationMetadata"))
60+
autoConfiguration(project(path: ":spring-boot-project:spring-boot-mail", configuration: "autoConfigurationMetadata"))
6061
autoConfiguration(project(path: ":spring-boot-project:spring-boot-reactor-netty", configuration: "autoConfigurationMetadata"))
6162
autoConfiguration(project(path: ":spring-boot-project:spring-boot-testcontainers", configuration: "autoConfigurationMetadata"))
6263
autoConfiguration(project(path: ":spring-boot-project:spring-boot-tomcat", configuration: "autoConfigurationMetadata"))
@@ -72,6 +73,7 @@ dependencies {
7273
configurationProperties(project(path: ":spring-boot-project:spring-boot-devtools", configuration: "configurationPropertiesMetadata"))
7374
configurationProperties(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "configurationPropertiesMetadata"))
7475
configurationProperties(project(path: ":spring-boot-project:spring-boot-jetty", configuration: "configurationPropertiesMetadata"))
76+
configurationProperties(project(path: ":spring-boot-project:spring-boot-mail", configuration: "configurationPropertiesMetadata"))
7577
configurationProperties(project(path: ":spring-boot-project:spring-boot-reactor-netty", configuration: "configurationPropertiesMetadata"))
7678
configurationProperties(project(path: ":spring-boot-project:spring-boot-test-autoconfigure", configuration: "configurationPropertiesMetadata"))
7779
configurationProperties(project(path: ":spring-boot-project:spring-boot-testcontainers", configuration: "configurationPropertiesMetadata"))

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/io/email.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TIP: See the {url-spring-framework-docs}/integration/email.html[reference docume
77

88
If `spring.mail.host` and the relevant libraries (as defined by `spring-boot-starter-mail`) are available, a default javadoc:org.springframework.mail.javamail.JavaMailSender[] is created if none exists.
99
The sender can be further customized by configuration items from the `spring.mail` namespace.
10-
See javadoc:org.springframework.boot.autoconfigure.mail.MailProperties[] for more details.
10+
See javadoc:org.springframework.boot.mail.autoconfigure.MailProperties[] for more details.
1111

1212
In particular, certain default timeout values are infinite, and you may want to change that to avoid having a thread blocked by an unresponsive mail server, as shown in the following example:
1313

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
plugins {
2+
id "java-library"
3+
id "org.springframework.boot.auto-configuration"
4+
id "org.springframework.boot.configuration-properties"
5+
id "org.springframework.boot.docker-test"
6+
id "org.springframework.boot.deployed"
7+
id "org.springframework.boot.optional-dependencies"
8+
}
9+
10+
description = "Spring Boot Mail"
11+
12+
dependencies {
13+
api(project(":spring-boot-project:spring-boot"))
14+
api("org.springframework:spring-context-support")
15+
api("org.eclipse.angus:jakarta.mail")
16+
17+
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
18+
19+
dockerTestImplementation(project(":spring-boot-project:spring-boot-test"))
20+
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support-docker"))
21+
dockerTestImplementation("org.assertj:assertj-core")
22+
dockerTestImplementation("org.awaitility:awaitility")
23+
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
24+
dockerTestImplementation("org.testcontainers:junit-jupiter")
25+
dockerTestImplementation("org.testcontainers:testcontainers")
26+
27+
testImplementation(project(":spring-boot-project:spring-boot-test"))
28+
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
29+
testImplementation(testFixtures(project(":spring-boot-project:spring-boot-autoconfigure")))
30+
testImplementation("org.assertj:assertj-core")
31+
testImplementation("org.awaitility:awaitility")
32+
testImplementation("org.junit.jupiter:junit-jupiter")
33+
testImplementation("org.mockito:mockito-core")
34+
testImplementation("org.mockito:mockito-junit-jupiter")
35+
36+
testRuntimeOnly("ch.qos.logback:logback-classic")
37+
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.mail;
17+
package org.springframework.boot.mail.autoconfigure;
1818

1919
import java.net.SocketTimeoutException;
2020
import java.security.cert.CertPathBuilderException;
@@ -95,9 +95,9 @@ class ImplicitTlsTests {
9595
private static final MailpitContainer mailpit = TestImage.container(MailpitContainer.class)
9696
.withSmtpRequireTls(true)
9797
.withSmtpTlsCert(MountableFile
98-
.forClasspathResource("/org/springframework/boot/autoconfigure/mail/ssl/test-server.crt"))
98+
.forClasspathResource("/org/springframework/boot/mail/autoconfigure/ssl/test-server.crt"))
9999
.withSmtpTlsKey(MountableFile
100-
.forClasspathResource("/org/springframework/boot/autoconfigure/mail/ssl/test-server.key"))
100+
.forClasspathResource("/org/springframework/boot/mail/autoconfigure/ssl/test-server.key"))
101101
.withPop3Auth("user:pass");
102102

103103
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@@ -108,9 +108,9 @@ void sendEmailWithSslEnabledAndCert() {
108108
this.contextRunner.withPropertyValues("spring.mail.host:" + mailpit.getHost(),
109109
"spring.mail.port:" + mailpit.getSmtpPort(), "spring.mail.ssl.enabled:true",
110110
"spring.mail.ssl.bundle:test-bundle",
111-
"spring.ssl.bundle.pem.test-bundle.truststore.certificate=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-ca.crt",
112-
"spring.ssl.bundle.pem.test-bundle.keystore.certificate=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-client.crt",
113-
"spring.ssl.bundle.pem.test-bundle.keystore.private-key=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-client.key",
111+
"spring.ssl.bundle.pem.test-bundle.truststore.certificate=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-ca.crt",
112+
"spring.ssl.bundle.pem.test-bundle.keystore.certificate=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-client.crt",
113+
"spring.ssl.bundle.pem.test-bundle.keystore.private-key=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-client.key",
114114
"spring.mail.properties.mail.pop3.host:" + mailpit.getHost(),
115115
"spring.mail.properties.mail.pop3.port:" + mailpit.getPop3Port())
116116
.run((context) -> {
@@ -137,9 +137,9 @@ void sendEmailWithoutSslWithCert() {
137137
this.contextRunner.withPropertyValues("spring.mail.host:" + mailpit.getHost(),
138138
"spring.mail.port:" + mailpit.getSmtpPort(), "spring.mail.properties.mail.smtp.timeout:1000",
139139
"spring.mail.ssl.bundle:test-bundle",
140-
"spring.ssl.bundle.pem.test-bundle.truststore.certificate=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-ca.crt",
141-
"spring.ssl.bundle.pem.test-bundle.keystore.certificate=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-client.crt",
142-
"spring.ssl.bundle.pem.test-bundle.keystore.private-key=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-client.key")
140+
"spring.ssl.bundle.pem.test-bundle.truststore.certificate=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-ca.crt",
141+
"spring.ssl.bundle.pem.test-bundle.keystore.certificate=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-client.crt",
142+
"spring.ssl.bundle.pem.test-bundle.keystore.private-key=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-client.key")
143143
.run((context) -> {
144144
JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
145145
assertThatException().isThrownBy(() -> mailSender.send(createMessage("Should fail")))
@@ -156,9 +156,9 @@ class StarttlsTests {
156156
private static final MailpitContainer mailpit = TestImage.container(MailpitContainer.class)
157157
.withSmtpRequireStarttls(true)
158158
.withSmtpTlsCert(MountableFile
159-
.forClasspathResource("/org/springframework/boot/autoconfigure/mail/ssl/test-server.crt"))
159+
.forClasspathResource("/org/springframework/boot/mail/autoconfigure/ssl/test-server.crt"))
160160
.withSmtpTlsKey(MountableFile
161-
.forClasspathResource("/org/springframework/boot/autoconfigure/mail/ssl/test-server.key"))
161+
.forClasspathResource("/org/springframework/boot/mail/autoconfigure/ssl/test-server.key"))
162162
.withPop3Auth("user:pass");
163163

164164
final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@@ -170,9 +170,9 @@ void sendEmailWithStarttlsAndCertAndSslDisabled() {
170170
"spring.mail.port:" + mailpit.getSmtpPort(),
171171
"spring.mail.properties.mail.smtp.starttls.enable:true",
172172
"spring.mail.properties.mail.smtp.starttls.required:true", "spring.mail.ssl.bundle:test-bundle",
173-
"spring.ssl.bundle.pem.test-bundle.truststore.certificate=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-ca.crt",
174-
"spring.ssl.bundle.pem.test-bundle.keystore.certificate=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-client.crt",
175-
"spring.ssl.bundle.pem.test-bundle.keystore.private-key=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-client.key",
173+
"spring.ssl.bundle.pem.test-bundle.truststore.certificate=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-ca.crt",
174+
"spring.ssl.bundle.pem.test-bundle.keystore.certificate=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-client.crt",
175+
"spring.ssl.bundle.pem.test-bundle.keystore.private-key=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-client.key",
176176
"spring.mail.properties.mail.pop3.host:" + mailpit.getHost(),
177177
"spring.mail.properties.mail.pop3.port:" + mailpit.getPop3Port())
178178
.run((context) -> {
@@ -188,9 +188,9 @@ void sendEmailWithStarttlsAndCertAndSslEnabled() {
188188
"spring.mail.port:" + mailpit.getSmtpPort(), "spring.mail.ssl.enabled:true",
189189
"spring.mail.properties.mail.smtp.starttls.enable:true",
190190
"spring.mail.properties.mail.smtp.starttls.required:true", "spring.mail.ssl.bundle:test-bundle",
191-
"spring.ssl.bundle.pem.test-bundle.truststore.certificate=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-ca.crt",
192-
"spring.ssl.bundle.pem.test-bundle.keystore.certificate=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-client.crt",
193-
"spring.ssl.bundle.pem.test-bundle.keystore.private-key=classpath:org/springframework/boot/autoconfigure/mail/ssl/test-client.key",
191+
"spring.ssl.bundle.pem.test-bundle.truststore.certificate=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-ca.crt",
192+
"spring.ssl.bundle.pem.test-bundle.keystore.certificate=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-client.crt",
193+
"spring.ssl.bundle.pem.test-bundle.keystore.private-key=classpath:org/springframework/boot/mail/autoconfigure/ssl/test-client.key",
194194
"spring.mail.properties.mail.pop3.host:" + mailpit.getHost(),
195195
"spring.mail.properties.mail.pop3.port:" + mailpit.getPop3Port())
196196
.run((context) -> {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.mail;
17+
package org.springframework.boot.mail.autoconfigure;
1818

1919
import java.nio.charset.Charset;
2020
import java.nio.charset.StandardCharsets;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.mail;
17+
package org.springframework.boot.mail.autoconfigure;
1818

1919
import jakarta.activation.MimeType;
2020
import jakarta.mail.internet.MimeMessage;
@@ -25,8 +25,8 @@
2525
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2727
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
28-
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration.MailSenderCondition;
2928
import org.springframework.boot.context.properties.EnableConfigurationProperties;
29+
import org.springframework.boot.mail.autoconfigure.MailSenderAutoConfiguration.MailSenderCondition;
3030
import org.springframework.context.annotation.Conditional;
3131
import org.springframework.context.annotation.Import;
3232
import org.springframework.mail.MailSender;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.mail;
17+
package org.springframework.boot.mail.autoconfigure;
1818

1919
import javax.naming.NamingException;
2020

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.mail;
17+
package org.springframework.boot.mail.autoconfigure;
1818

1919
import java.util.Map;
2020
import java.util.Properties;
2121

2222
import org.springframework.beans.factory.ObjectProvider;
2323
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2424
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
25-
import org.springframework.boot.autoconfigure.mail.MailProperties.Ssl;
25+
import org.springframework.boot.mail.autoconfigure.MailProperties.Ssl;
2626
import org.springframework.boot.ssl.SslBundle;
2727
import org.springframework.boot.ssl.SslBundles;
2828
import org.springframework.context.annotation.Bean;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.mail;
17+
package org.springframework.boot.mail.autoconfigure;
1818

1919
import jakarta.mail.MessagingException;
2020

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
/**
1818
* Auto-configuration for email support.
1919
*/
20-
package org.springframework.boot.autoconfigure.mail;
20+
package org.springframework.boot.mail.autoconfigure;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"groups": [],
3+
"properties": [
4+
{
5+
"name": "spring.mail.test-connection",
6+
"description": "Whether to test that the mail server is available on startup.",
7+
"sourceType": "org.springframework.boot.autoconfigure.mail.MailProperties",
8+
"type": "java.lang.Boolean",
9+
"defaultValue": false
10+
}
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.boot.mail.autoconfigure.MailSenderAutoConfiguration
2+
org.springframework.boot.mail.autoconfigure.MailSenderValidatorAutoConfiguration
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.mail;
17+
package org.springframework.boot.mail.autoconfigure;
1818

1919
import java.util.Properties;
2020

spring-boot-project/spring-boot-starters/spring-boot-starter-mail/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ description = "Starter for using Java Mail and Spring Framework's email sending
66

77
dependencies {
88
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter"))
9-
api("org.springframework:spring-context-support")
10-
api("org.eclipse.angus:jakarta.mail")
9+
api(project(":spring-boot-project:spring-boot-mail"))
1110
}

0 commit comments

Comments
 (0)