Forced rendered node view results in empty node links In order to send html email using drupal/swiftmailer I load and view a node. 

Then I pass it to the rendere. In the email sent, generated node__links are empty. As node_links uses #LazyBuilder, Im then not sure to use the correct way.

hook_mail

function mymodule_mail($key, &amp;$message, $params) {
   switch ($key) {
       case 'mail_node':
           $message['from'] = \Drupal::config('system.site')-&gt;get('mail');
           $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
           $message['subject'] = t('Mail subject');

           $node = Node::load($params['nid']);
           $view_builder = \Drupal::entityTypeManager()-&gt;getViewBuilder('node');


           $body_data = [
               '#theme' =&gt; 'mymodule_mail_node',
               '#content' =&gt; $view_builder-&gt;view( $node ),
           ];

           $message['body'][] = \Drupal::service('renderer')-&gt;render($body_data);
       break;
       }
 }


mymodule--mail-node.html.twig

 {# simply render the whole body #}
 {{ body }}


output results in mail

&lt;!-- THEME DEBUG --&gt;
&lt;!-- THEME HOOK: 'links__node' --&gt;
&lt;!-- FILE NAME SUGGESTIONS:
    x links--node.html.twig
    * links.html.twig
--&gt;
&lt;!-- BEGIN OUTPUT from 'core/themes/classy/templates/content/links--node.html.twig' --&gt;

&lt;!-- END OUTPUT from 'core/themes/classy/templates/content/links--node.html.twig' --&gt;


When I render the same content into an html page, node__links are correctly filled. 

Any recommandation would be appreciate.
Thanks
Use renderPlain():

$message['body'][] = \Drupal::service('renderer')-&gt;renderPlain($body_data);


From the documentation:


  Renders final HTML in situations where no assets are needed.
  
  Calls ::render() in such a way that placeholders are replaced.
  
  Useful for instance when rendering the values of tokens or emails,
  which need a render array being turned into a string, but do not need
  any of the bubbleable metadata (the attached assets and cache tags).


Source: Renderer::renderPlain



"When I render the same content into an html page, node__links are correctly filled."

render() in a page works, because the page has a render context for the metadata to bubble up, so that the placeholders can be replaced later.