Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send email reactive in spring web-flux

I'd like to stay complete reactive within my new spring application. Therefor I use web-flux/ reactor and ReactiveRepository with MongoDB.

Do you know how to integrate java-mail reactively into the tech-stack? Any alternatives?

like image 429
kalamar Avatar asked Jun 28 '18 22:06

kalamar


1 Answers

The only useful non-blocking SMTP client I found and still use is https://vertx.io/docs/vertx-mail-client/java/
I even integrated it with spring-webflux and mongodb-driver-reactivestreams so that they share the same Netty EventLoopGroup.

Mono.create<MailResult> { sink ->
  mailClient.sendMail(email) { asyncResult ->
    if (asyncResult.succeeded()) {
      sink.success(asyncResult.result()
    } else {
      sink.error(asyncResult.cause()
    }
  }
}
like image 83
Dmytro Voloshyn Avatar answered Oct 04 '22 04:10

Dmytro Voloshyn