How to take action on a state change of a task run? (task-level state handler)

you can call some function that sends an email from the part of the code where you need it - you can do that using this collection:

Starting from 2.0.1 release, you can even use .map() syntax for that