Get generated spool file Swiftmailer/Symfony2

633 views Asked by At

I am moving from instant sending to spooling messages using Swiftmailer/Symfony2. I have everything working but I can't seem to get the path to the generated file after I do $mailer->send(). SF2 or Swiftmailer creates the file in my spool directory, but through the Swiftmailer instance is there a way that I can get that generated filename?

In case someone is wondering, I would like to get that file to keep a record of emails sent.. and I would like to include the serialization of that file...

Note: looping through the directory and getting the files is not an option as multiple files can be created relatively at the same time...

Update #1

Here is my dirty way around this..

  1. Create a new spool and set a temporary path with a hash..something like $newSpool = new \Swift_FileSpool($this->container->getParameter('swiftmailer.spool.default.file.path')."/".$hash/
  2. After the $mailer->send() the file will be inside the hash folder
  3. Read that folder and in theory it should only contain 1 file
  4. Log any desire information and the file content and name
  5. Move the file out of the hash folder to the actual spool directory to continue the process normally.

Again, this is my dirty way of getting a hold of this file name... sadly I don't see any other way around at this moment and the documentation is not helping as I can't find how to use Swift Events in 2.8+

I will leave this question opened until a better answer comes up.

0

There are 0 answers