Skip to content

Commit

Permalink
Update documentation for the mailer service
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier committed Feb 16, 2020
1 parent bc3a7d0 commit 78eb408
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions docs/src/main/asciidoc/mailer.adoc
Expand Up @@ -100,18 +100,24 @@ ReactiveMailer reactiveMailer;
There are 2 APIs:

* `io.quarkus.mailer.Mailer` provides the imperative (blocking and synchronous) API;
* `io.quarkus.mailer.ReactiveMailer` provides the reactive (non-blocking and asynchronous) API
* `io.quarkus.mailer.reactive.ReactiveMailer` provides the reactive (non-blocking and asynchronous) API

NOTE: The two APIs are equivalent feature-wise. Actually the `Mailer` implementation is built on top of the `ReactiveMailer` implementation.

[NOTE]
.Deprecation
====
`io.quarkus.mailer.ReactiveMailer` is deprecated in favor of `io.quarkus.mailer.reactive.ReactiveMailer`.
====

To send a simple email, proceed as follows:

[source, java]
----
// Imperative API:
mailer.send(Mail.withText("to@acme.org", "A simple email from quarkus", "This is my body."));
// Reactive API:
CompletionStage<Void> stage = reactiveMailer.send(Mail.withText("to@acme.org", "A reactive email from quarkus", "This is my body."));
Uni<Void> stage = reactiveMailer.send(Mail.withText("to@acme.org", "A reactive email from quarkus", "This is my body."));
----

For example, you can use the `Mailer` in a JAX-RS endpoint as follows:
Expand All @@ -130,10 +136,16 @@ public Response sendASimpleEmail() {
public CompletionStage<Response> sendASimpleEmailAsync() {
return reactiveMailer.send(
Mail.withText("to@acme.org", "A reactive email from quarkus", "This is my body"))
.subscribeAsCompletionStage()
.thenApply(x -> Response.accepted().build());
}
----

[NOTE]
----
With the `quarkus-resteasy-mutiny` extension, you can return an instance of `Uni` directly.
----

With such a JAX-RS resource, you can check that everything is working with:

[source, bash]
Expand Down Expand Up @@ -215,6 +227,7 @@ public CompletionStage<Response> send() {
// the template looks like: Hello {name}!
.data("name", "John") <3>
.send() <4>
.subscribeAsCompletionStage()
.thenApply(x -> Response.accepted().build());
}
----
Expand Down Expand Up @@ -325,8 +338,9 @@ If you need fine control on how the mail is sent, for instance if you need to re

Three API flavors are exposed:

* the Axle client (`io.vertx.axle.ext.mail.MailClient`), using `CompletionStage` and Reactive Streams `Publisher`
* the RX Java 2 client (`io.vertx.reactivex.ext.mail.MailClient`)
* the Mutiny client (`io.vertx.mutiny.ext.mail.MailClient`)
* the Axle client (`io.vertx.axle.ext.mail.MailClient`), using `CompletionStage` and Reactive Streams `Publisher` - deprecated, it is recommended to switch to the Mutiny client
* the RX Java 2 client (`io.vertx.reactivex.ext.mail.MailClient`) - deprecated, it is recommended to switch to the Mutiny client
* the bare client (`io.vertx.ext.mail.MailClient`)

Check the link:vertx[Using Vert.x guide] for further details about these different APIs and how to select the most suitable for you.
Expand Down

0 comments on commit 78eb408

Please sign in to comment.