Sending Email with Scala and Akka Actors
How many apps have you built where you have to send out emails for any variety of reasons?
As I make my way learning about Akka Actors I decided to use them in one scala app I’m working on.
I decided to used them for this task not just because of the scalability and easy concurrent model but also for 3 main reasons.
- The builtin configurable supervisor strategy allows you to monitor child workers and decide what policy applies should there be an exception.
- I could easily reschedule email delivery attempts on common email exception often times thrown by SMTP servers.
- Actor routers allow you to dispatch messages to a pool of actors in an intelligent way. In this case we use the SmallestMailboxRouter which sends messages to actors in the pool with a smaller workload.
The code is dependent on apache commons-email and some built in play! framework 2 stuff but getting rid of it would be trivial for anyone wanting to reuse it on a different context.