How to render a node with absolute URL to use in a mail? I have to send node content by mail using an API. I manage to load and render the content to use it with my API class, and to send it.
But when Drupal render the node, all URLs and image SRC are relatives, and it can't be used in a mail.

Here is the code I got so far

$node = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;load($test_node); // $test_node is a (integer) NID
$renderBuilder = \Drupal::entityTypeManager()-&gt;getViewBuilder('node');
$node_view = $renderBuilder-&gt;view($node, $view_mode); // $view_mode is define in my admin settings
$html = \Drupal::service('renderer')-&gt;render($node_view); // I also tried renderRoot and renderPlain
dump($html); // URLs are relatives
exit;


I really search for days now, and I cannot figure how to tell Drupal Renderer to use absolute URL to generate the HTML string.
Two possible approaches:


Find the URLs in preprocess targeting this specific view mode and apply setAbsolute(), see for example How do I render the absolute URL of a referenced entity in a simplenews newsletter? 
Apply a regex on the rendered output $html or use Html::transformRootRelativeUrlsToAbsolute() like added recently to the core MailManager:

$html = Markup::create(Html::transformRootRelativeUrlsToAbsolute((string) $html, \Drupal::request()-&gt;getSchemeAndHttpHost()));


Source: https://git.drupalcode.org/project/drupal/commit/530f7ac


By the way, use instead of render() the method renderPlain(), see How to deal with Bubbleable Metadata when there&#39;s no rendering context and no render array