How do I send a mail with attachment? I try with this, but no success:

$params = [
  'body' =&gt; 'My body',
  'subject' =&gt; 'My subject',
];

// I check by debug this code and $file get the right file
$file = File::load($myfile_id);

$attachment = [
  'filepath' =&gt; $file-&gt;getFileUri(),
];

$params['attachment'] = $attachment;

// This send a empty mail, without subject and not body
$send = \Drupal::service('plugin.manager.mail')-&gt;mail('mymodule', 'mykey', 'myuser@gmail.com', 'es', $params);


Why doesn't \Drupal::service('plugin.manager.mail')-&gt;mail work?

Then I tried this and it worked fine, but without attachments.

$system = \Drupal::service('plugin.manager.mail')-&gt;getInstance(array('module' =&gt; 'mymodule', 'key' =&gt; 'mykey'));

$file = File::load($myfile_id);

$params = [
  'headers' =&gt; [
    'MIME-Version' =&gt; '1.0',
    'Content-Type' =&gt; 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' =&gt; '8Bit',
    'X-Mailer' =&gt; 'Drupal',
  ],
  'to' =&gt; 'myuser@gmail.com',
  'body' =&gt; 'My body',
  'subject' 'My subject',
  // I try with:
  'attachment' =&gt; $file;
  // or
  'attachment' =&gt; ['filepath' =&gt; $file-&gt;getFileUri()];
  // with not success
];

// the mail was sent but without attachment
$send = $system-&gt;mail($params);


How do I send a mail with attachment on Drupal 8?
Drupal core doesn't support mail attachments/HTML mails.

You need to use an alternative mail implementation, like the Swift Mailer module. 

Also, the reason the first implementation doesn't work is because you need to go through a hook_mail() implementation instead. See how core does it.