Custom wather data sent by emaill

{
  "input" : {
    "search" : { ... }
  },
  "condition" : { ... },
  "transform" : {
    "script" : "return [ 'errors' : ctx.payload.hits.hits.collect { it._source.message } ]"
  }
}

I want to loop through data errors, and then reorganize the data information, send out by email, what should I do?

Such as
servers:  xxxx
times:  xxxx
errors:  xxxx