Sending email

I'm looking for best practices for sending email as reaction to a
command (or an event).
I know that sending email is not part of the problem that the Axon
Framework should solve, but I am certain that it is part of many
applications built on top of the Axon Framework. So, how do you guys
do it?

Hi Per,

the functional requirement specification should give you a very good indication.
It could be, for example:
when a user has registered, the system sends a confirmation email

In other words: use an event handler that sends a confirmation email when the “UserRegisteredEvent” comes by. You can use the query database to find any information not included in the event itself.

Cheers,

Allard

Thanks. I was also thinking about how to actually handle the mail
sending. Like having an asynchronous command handler that queues the
mail and handles them "later". Of course this is also dependent on the
actual requirements, but I was thinking in more general terms.

That was supposed to be "an asynchronous event handler "

Hi Per,

this handler is typically one that can be made asynchronous without much trouble. However, if you have a local smtp relay server, you could easily provide it with the email message synchronously. It really depends on how long it takes to build the email and how long you want to wait for it. But since sending emails is an asynchronous process (you can’t wait for it to be delivered in an inbox), you might as well make the event handler asynchronous.

Cheers,

Allard

Any sample usage for AsyncEventHandler, my async handler is not getting picked up for sending email method which takes seconds and freezes up the sync processing.

what has been done is

@AsynchronousEventListener(sequencingPolicyClass = FullConcurrencyPolicy.class) is the class annotation and the class implements the SequencingPolicy interface and has an EventHandler method. This works without the AsynchEventListner but is slow for email integration and needs to be async to not lock up the jvm synchronously.

Any thoughts on what could I be missing? Any sample code?

Cheers…

Never mind… I was missing the spring component annotation and it worked.

Annotating @Component on the class made it work.

Cheers…