magento2.4.2 – Magento 2.4.2 How to attched PDF in Email?

This should work:)

on your di.xml VendorModuleetcdi.xml

<preference for="MagentoSalesModelOrderEmailSenderBuilder"     type="ModuleVendorModelMailSenderBuilder"/>

On VendorModuleModelOrder

  <?php

namespace VendorModuleModelMail;


class SenderBuilder extends MagentoSalesModelOrderEmailSenderBuilder
{
    /**
     * Prepare and send email message
     *
     * @return void
     */
    public function send()
    {
        $vars  = $this->templateContainer->getTemplateVars();
        $order = $vars('order');
        
        if(isset( $order))
        {
            
                $fileName = get your file name here
                $file     = get your file here;

                $this->transportBuilder->addAttachment($file, $fileName, 'application/pdf');
            
        }

        $this->configureEmailTemplate();

        $this->transportBuilder->addTo(
            $this->identityContainer->getCustomerEmail(),
            $this->identityContainer->getCustomerName()
        );

        $copyTo = $this->identityContainer->getEmailCopyTo();

        if (!empty($copyTo) && $this->identityContainer->getCopyMethod() == 'bcc') {
            foreach ($copyTo as $email) {
                $this->transportBuilder->addBcc($email);
            }
        }

        $transport = $this->transportBuilder->getTransport();
        $transport->sendMessage();
    }
}