-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40990 from cescoffier/mailer-tls-registry
Add support for the TLS registry to the mailer extension
- Loading branch information
Showing
34 changed files
with
1,001 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,28 +362,100 @@ More details about this extension and its configuration can be found in the http | |
[TIP] | ||
For more information about the Mailer configuration please refer to the <<configuration-reference,Configuration Reference>>. | ||
|
||
== Configuring a trust store | ||
== Configuring TLS | ||
|
||
If your SMTP requires a trust store, you can configure the trust store as follows: | ||
SMTP provides various way to use TLS: | ||
|
||
- StartTLS: The client connects to the server using a plain connection and then upgrades to a secure connection. | ||
- SSL/TLS: The client connects to the server using a secure connection from the start. | ||
|
||
=== Configuring STARTTLS | ||
|
||
To use `STARTTLS`, you need to configure the `start-tls` property to `REQUIRED` or `OPTIONAL` and set `tls` to `false`: | ||
|
||
[source, properties] | ||
---- | ||
quarkus.mailer.tls=false | ||
quarkus.mailer.start-tls=REQUIRED | ||
---- | ||
|
||
Setting `tls` to `false` ensure we connect using a plain connection and then upgrade to a secure connection using `STARTTLS`. | ||
|
||
To configure the trust store, you can use a _named_ TLS configuration stored in the xref:./tls-registry-reference.adoc[TLS registry]: | ||
|
||
[source, properties] | ||
---- | ||
quarkus.mailer.tls=false | ||
quarkus.mailer.start-tls=REQUIRED | ||
quarkus.mailer.tls-configuration-name=my-mailer # Reference the named configuration | ||
quarkus.tls.my-mailer.trust-store.pem.certs=server-cert.pem # Configure the trust store | ||
---- | ||
|
||
While not recommended, you can trust all certificates by setting `quarkus.tls.trust-all` to `true`: | ||
|
||
[source, properties] | ||
---- | ||
quarkus.mailer.tls=false | ||
quarkus.mailer.start-tls=REQUIRED | ||
quarkus.mailer.tls-configuration-name=my-mailer # Reference the named configuration | ||
quarkus.tls.my-mailer.trust-all=true | ||
---- | ||
|
||
Alternatively, you can use the _deprecated_ `quarkus.mailer.trust-store.paths` and `quarkus.mailer.trust-all` properties: | ||
|
||
[source, properties] | ||
---- | ||
quarkus.mailer.tls=false | ||
quarkus.mailer.start-tls=REQUIRED | ||
quarkus.mailer.truststore.paths=target/certs/mailpit-ca.crt | ||
---- | ||
|
||
[source, properties] | ||
---- | ||
quarkus.mailer.host=... | ||
quarkus.mailer.port=... | ||
quarkus.mailer.ssl=true | ||
quarkus.mailer.trust-store.paths=truststore.jks # the path to your trust store | ||
quarkus.mailer.trust-store.password=secret # the trust store password if any | ||
quarkus.mailer.trust-store.type=JKS # the type of trust store if it can't be deduced from the file extension | ||
quarkus.mailer.tls=false | ||
quarkus.mailer.start-tls=REQUIRED | ||
quarkus.mailer.trust-all=true | ||
---- | ||
|
||
Quarkus mailer supports JKS, PKCS#12 and PEM trust stores. | ||
For PEM, you can configure multiple files. | ||
For JKS and PKCS#12, you can configure the password if any. | ||
=== Configuring SSL/TLS | ||
|
||
`quarkus.mailer.trust-store.type` is optional and allows configuring the type of trust store (among `JKS`, `PEM` and `PKCS`). | ||
When not set, Quarkus tries to deduce the type from the file name. | ||
To establish a TLS connection, you need to configure a _named_ configuration using the xref:./tls-registry-reference.adoc[TLS registry]: | ||
|
||
NOTE: You can also configure `quarkus.mailer.trust-all=true` to bypass the verification. | ||
[source, properties] | ||
---- | ||
quarkus.tls.my-mailer.trust-store.p12.path=server-truststore.p12 | ||
quarkus.tls.my-mailer.trust-store.p12.password=secret | ||
quarkus.mailer.tls-configuration-name=my-mailer # Reference the named configuration | ||
---- | ||
|
||
WARNING: When using the mailer, using a _named_ configuration is required to avoid conflicts with other TLS configurations. | ||
The mailer will not use the default TLS configuration. | ||
|
||
When you configure a _named_ TLS configuration, TLS is enabled by default. | ||
If your SMTP server uses a valid (trusted) certificate, and thus do not require a specific TLS configuration, you need to enable TLS explicitly (as you do not have to configure a trust store): | ||
|
||
[source, properties] | ||
---- | ||
quarkus.mailer.tls=true | ||
---- | ||
|
||
|
||
|
||
[IMPORTANT] | ||
==== | ||
When `quarkus.tls.trust-all` is set to `true`, the trust store configuration is ignored. This is not recommended for production. | ||
Also, we recommend avoiding using `quarkus.tls.trust-all`, and use a named configuration instead if `trust-all` is required: | ||
[source, properties] | ||
---- | ||
quarkus.tls.my-mailer.trust-all=true | ||
quarkus.mailer.tls-configuration-name=my-mailer # Reference the named configuration | ||
---- | ||
You can also use the deprecated `quarkus.mailer.trust-all=true` property. | ||
==== | ||
|
||
== Multiple mailer configurations | ||
|
||
|
@@ -476,7 +548,7 @@ You need to switch on 2-Step Verification at https://myaccount.google.com/securi | |
|
||
When done, you can configure your Quarkus application by adding the following properties to your `application.properties`: | ||
|
||
With TLS: | ||
With `STARTTLS`: | ||
|
||
[source,properties] | ||
---- | ||
|
@@ -491,15 +563,15 @@ quarkus.mailer.password=YOURGENERATEDAPPLICATIONPASSWORD | |
quarkus.mailer.mock=false # In dev mode, prevent from using the mock SMTP server | ||
---- | ||
|
||
Or with SSL: | ||
Or with TLS/SSL: | ||
|
||
[source,properties] | ||
---- | ||
quarkus.mailer.auth-methods=DIGEST-MD5 CRAM-SHA256 CRAM-SHA1 CRAM-MD5 PLAIN LOGIN | ||
[email protected] | ||
quarkus.mailer.host=smtp.gmail.com | ||
quarkus.mailer.port=465 | ||
quarkus.mailer.ssl=true | ||
quarkus.mailer.tls=true | ||
[email protected] | ||
quarkus.mailer.password=YOURGENERATEDAPPLICATIONPASSWORD | ||
|
@@ -532,6 +604,7 @@ ses.from=an email address from the verified domain | |
quarkus.mailer.host=${ses.smtp} | ||
quarkus.mailer.port=587 | ||
quarkus.mailer.tls=false | ||
quarkus.mailer.username=${ses.user} | ||
quarkus.mailer.password=${ses.password} | ||
quarkus.mailer.start-tls=REQUIRED | ||
|
@@ -565,7 +638,7 @@ quarkus.mailer.port=465 | |
quarkus.mailer.username=${mailjet.api-key} | ||
quarkus.mailer.password=${mailjet.secret-key} | ||
quarkus.mailer.start-tls=OPTIONAL | ||
quarkus.mailer.ssl=true | ||
quarkus.mailer.tls=true | ||
quarkus.mailer.login=REQUIRED | ||
quarkus.mailer.from=${mailjet.from} | ||
|
@@ -591,13 +664,14 @@ quarkus.mailer.port=465 | |
quarkus.mailer.username=${sendgrid.username} | ||
quarkus.mailer.password=${sendgrid.key} | ||
quarkus.mailer.start-tls=OPTIONAL | ||
quarkus.mailer.ssl=true | ||
quarkus.mailer.login=REQUIRED | ||
quarkus.mailer.from=... | ||
quarkus.mailer.tls=true | ||
quarkus.mailer.mock=false # In dev mode, prevent from using the mock SMTP server | ||
---- | ||
|
||
|
||
[[configuration-reference]] | ||
== Mailer Configuration Reference | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.