Problem/Motivation
<?php
$message['body'][] = (string) \Drupal::service('renderer')->renderPlain($build);
?>
That breaks sending HTML mails for example with swift mailer, which tries to be correct and escapes non-safe HTML.
Proposed resolution
Remove the string casts.