MDL-46589 scheduled task does not send emails

Thanks to  Luděk Šulák  for the patch