How do I use a template file for preparing HTML message body for emails? I want to use a template file for preparing the email message body using the table tag, and putting the submitted form data by user in table rows. I have implemented hook_mail() with the following code. 

function get_price_mail($key, &amp;$message, $params) {
  switch ($key) {
    case 'mail_to_eberhard':
      $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
      $message['subject'] = t('Factory Purchase - ').\Drupal::config('system.site')-&gt;get('name');;
      $message['body'][] = $params['message'];
      break;
   }
}


I created a template file (get_price/templates/mail-to-eberhard.html.twig), but the message body is not using my template file.

How do I make Drupal 8 use my template file?
So here is the answer:
Inside the hook theme function of your module use this code

function get_price_theme() {
  return [
    'mail_to_eberhard' =&gt; array (
        'template' =&gt; 'mail-to-eberhard',  // TWIG File
        'variables' =&gt; array('submitted_data'=&gt;[]),
    ),
  ];
} 


where variables is the array of parameter you want to send to the template file. Now create a template file named as mail-to-eberhard.html.twig inside your modules template folder. 
Then inside the hook_mail() alter function use this code.

function get_price_mail($key, &amp;$message, $params) {
  switch ($key) {
    case 'mail_to_eberhard':
      $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
      //$message['from'] = \Drupal::config('system.site')-&gt;get('mail');
      $message['subject'] = t('Factory Purchase - ').\Drupal::config('system.site')-&gt;get('name');;
      //$message['subject'] = t('Article created: @title', array('@title' =&gt; $params['node_title']), $options);
      // Render the template to HTML
      // Set up email template
      $body_data = array (
         '#theme' =&gt; 'mail_to_eberhard',
         '#submitted_data' =&gt; $params['message']
      );
      //$message['body']['#theme'] = 'mail_to_eberhard';
      $message['body'][] = \Drupal::service('renderer')-&gt;render($body_data);
      break;
  }
} 


now inside you template file you can use the array variables like this

You have received one new message from the Get Price Tab.&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Full Name&lt;/b&gt; : {{ submitted_data['user_full_name'] }}&lt;br/&gt;
&lt;b&gt;Email&lt;/b&gt; : {{ submitted_data['user_email'] }}&lt;br/&gt;
&lt;b&gt;Phone&lt;/b&gt; : {{ submitted_data['user_number'] }}&lt;br/&gt;
&lt;b&gt;State&lt;/b&gt; : {{ submitted_data['user_state'] }}&lt;br/&gt;
&lt;b&gt;Product SKU&lt;/b&gt; : {{ submitted_data['product_sku'] }}&lt;br/&gt;
&lt;b&gt;Product URL&lt;/b&gt; : &lt;a href='{{ submitted_data['product_url'] }}'&gt;{{ submitted_data['product_url'] }}&lt;/a&gt;
&lt;br/&gt;&lt;b&gt;Message&lt;/b&gt; : {{ submitted_data['user_message'] }`