I took the plunge and switched from swiftmailer to symfony_mailer in StratosERP on the weekend, and it was surprisingly simple!
This snippet of code generates a pdf file using entity_print with wkhtmltopdf in the private filesystem, creates a new email, attaches the file and also takes a text_format field for the body and sends it.
// Create the Print engine plugin. $printEngine = $this->printEngine->createSelectedInstance('pdf'); $filename = 'output_filename.pdf'; $uri = $this->printBuilder->savePrintable([$entity], $printEngine, 'private', $filename); $email = $this->emailFactory->newTypedEmail('se_email', $entity->bundle()) ->setFrom(\Drupal::currentUser()->getEmail()) ->setTo('test@test.com') ->attachFromPath($uri) ->setSubject('Test email with attachment') ->setBody([ '#type' => 'processed_text', '#text' => $email_text['value'], '#format' => $email_text['format'], ]); $result = $email->send();