private function get_unique_users() : moodle_recordset {
        global $DB;

        $subsql = 'SELECT DISTINCT(useridto) as id
                     FROM {message_email_messages}
                    WHERE id <= ?';

        $sql = "SELECT *
                  FROM {user} u
                 WHERE id IN ($subsql)";

        return $DB->get_recordset_sql($sql, [$this->maxid]);
    }