code: private function attachFiles(Message $message, Email $email)
      {
          if (! $email->hasAttachments()) {
              return;
          }
          $attachments = $email->getComputedAttachments();
  
          // Get old message parts
          /** @var Mime\Message $mimeMessage */
          $mimeMessage = $message->getBody();
          $oldParts = $mimeMessage->getParts();
  
          // Generate a new Mime\Part for each attachment
          $attachmentParts = [];
          $info = null;
          foreach ($attachments as $key => $attachment) {
              // If the attachment is an array with "parser_name" and "value" keys, cast it into an Attachment object
              if (is_array($attachment) && isset($attachment['parser_name'], $attachment['value'])) {
                  $attachment = Attachment::fromArray($attachment);
              }
  
              $parserName = $this->resolveParserNameFromAttachment($attachment);
              if (! $this->attachmentParserManager->has($parserName)) {
                  throw new Exception\ServiceNotCreatedException(
                      sprintf('The attachment parser "%s" could not be found', $parserName)
                  );
              }
  
              /** @var AttachmentParserInterface $parser */
              $parser = $this->attachmentParserManager->get($parserName);
              $attachmentValue = $attachment instanceof Attachment ? $attachment->getValue() : $attachment;
              $part = $parser->parse($attachmentValue, is_string($key) ? $key : null);
  
              $part->charset = $email->getCharset();
              $attachmentParts[] = $part;
          }
  
          // Create a new body for the message, merging the attachment parts and all the old parts
          $body = new Mime\Message();
          $body->setParts(array_merge($oldParts, $attachmentParts));
          $message->setBody($body);
      }
docs: Attaches files to the message if any
  @param Message $message
  @param Email $email
  @throws Exception\InvalidAttachmentException
  @throws Exception\ServiceNotCreatedException
  @throws NotFoundExceptionInterface
  @throws ContainerExceptionInterface
  @throws InvalidArgumentException