Symfony 5 – Mailer – Attach pdf from assets?

  assets, attachment, mailer, pdf, symfony

in my symfony 5 project, I want to attach a .pdf to a mail with Mailer.

My pdf file was dropped in the assets, then copied with webpack encore in the public/build folder of my project. It is therefore versioned.

I would like, when sending an email, to be able to retrieve the file to attach it to the email.

I have already tried something like this:

    private $mailer;
    private $twig;
    private $package;

    public function __construct(MailerInterface $mailer, Environment $twig, $publicDir)
        $this->mailer = $mailer;
        $this->twig = $twig;
        $this->package = new Package(new JsonManifestVersionStrategy(sprintf('%s/build/manifest.json', $publicDir)));

        public function sendCustomerSubscriptionCreatedMail(StripeSubscription $subscription)

        $email = (new TemplatedEmail())
                ->to(new Address($user->getEmail(), $user->getNom()))
                    'subscription' => $subscription,
                ->attachFromPath($this->package->getUrl('files/manuels/Manuel utilisateurs - Salaries.pdf')); //here is the path for my .pdf files (in public/build/files/manuels/Manuel utilisateurs - Salaries.pdf)


        return $email;

But I’ve this error :

Path "files/manuels/Manuel utilisateurs – Salaries.pdf" is not

Can someone help me please ?

Source: Symfony Questions