Adding attachment using Swiftmailer I am trying to add an attachment to an email from a form_submit. I can see the attachment loading in the hook_mail() before the email sends, but no attachment is coming through. I also tried to use the swiftmailer_swiftmailer_attach() hook and that doesn't work. The emails are coming over with Content-Type: multipart/alternative;

Here is the code:

// from submitForm()
$params['message'] = $body;
$mail_manager = \Drupal::getContainer()-&gt;get('plugin.manager.mail');

$mail_manager-&gt;mail('so_assets', 'banner_email', 'test@test.com', \Drupal::languageManager()-&gt;getDefaultLanguage()-&gt;getId(), [
  //'content_type' =&gt; "text/html; charset=UTF-8; format=flowed; delsp=yes",
  'from' =&gt; 'test@test.com',
  'message' =&gt; $body,
  'myattachment' =&gt; $store_logo[0],
]);


// in .module file
function so_assets_mail($key, &amp;$message, $params) {
  $options = array(
    'langcode' =&gt; $message['langcode'],
  );
  //var_dump($params['myattachment']); die(); // I can see the managed file ID here and load it.
  switch ($key) {
    case 'banner_email':
      $message['from'] = \Drupal::config('system.site')-&gt;get('mail');
      $message['subject'] = t('New Request');
      $message['body'][] = $params['message'];
      //$message['params']['files'][] = \Drupal\file\Entity\File::load($params['myattachment']);
      break;
  }
}
// I tried this, with and without the file attachment commented out in the hook_mail()
function so_assets_swiftmailer_attach($key) {
  return \Drupal\file\Entity\File::load(5130);
}
Swiftmailer currently expects a plain \stdClass object in files as this part hasn't been fully ported from D7. See https://www.drupal.org/node/2713651.

So you need to do something like

$file = (object) [
'filename' =&gt; $file-&gt;getFilename(),
'uri' =&gt; $file-&gt;getFileUri(),
'filemime' =&gt; $file-&gt;getMimeType(),
];
$message['params']['files'][] = $file;